Qt graphical button - qt

I'd like to create a button in Qt that is the size and shape of a PNG that I give it. I've tried using a QToolButton with setAutoRaise set to true so that the 3D frame only appears on mouseover and press, but I don't want that 3D frame to extend beyond the PNG. Setting the icon size and/or the button's min and max sizes isn't helping.
In other words, I'd like the functionality of buttons like on (say) iOS, instead of something that one would expect on a Windows dialog box. The chrome that QToolButton provides (the 3D frame) is great and I still want that sort of behavior, but it seems like I'd have to do everything by hand -- ie, draw the mouseover, depressed, and disabled versions of the button.
Is there some way to treat a QToolButton's icon as the entire extents of the button? Or is there another control that I could use instead?

Related

Custom shaped menu with shadow in Qt

I'd like to create a context menu looking similar to this one:
I read suggestions on the web that QWidget::setMask() should be used to create a shape. But how can it fit the variable number of items then? Moreover, the same menu item may take more or less screen space on different machines.
Another question is how to create a shadow around this custom shape? As far as I understand, the mask allows to crop the widget, but not to make it semi-transparent.
I don’t found an easy way to do that! But here goes a way!
Instead of using the Qt mask API, I've used a frame-less widget with transparency enabled!
To draw the shadow, I've used radial gradient!
You can change the size of the menu before opening it, however you can’t resize it after opened (for example resize with mouse).
It’s quite easy add or remove widgets, just respect the layout margin to not draw outside the bounds destined to widgets. To simplify your life I created an inherited class of QPushButton with colors you can easily customize with style sheet.
See the result:
You can browse the source
Hope that helps!

RGtk cursor shapes

Morning,
I'm currently building a R/Gtk2 application (mostly through gWidgets actually) and I would like to change the cursor shape to something sensible in different contexts. Specifically, I require a "zoom in" and "zoom out" shape when the appropriate tool is activated.
This post (how can i change the shape mouse cursor in gWidgets RGtk2?) gives good information on the syntax to use.
My problem is that in the list of available cursors (e.g. help("gdk-Cursors") ) includes all sort of weird and wonderful things (boat, clock and coffee mug....) but none of the ordinary shapes such as zoom in, zoom out, text edit...
I guess I could use an external image to define cursor I like (cf. Change mouse cursor of a widget in gWidgetsRGtk2) but really, I find it hard to believe that RGtk does not ship with a set of sane cursor shapes.
Surely I'm missing something, but where can I find cursors of "normal" shape ?

How to change QIcon color?

I am working on a custom control box (that min,max/restore/close button in the top right of your Windows titlebar) for my new application. I use closeIcon = style.standardIcon(QStyle.SP_TitleBarCloseButton) to get the correct icon for them. See the full code here in my other SO question. What I got is a black icon. In which I need the white version when it's in hover state.
Can we .. I don't know, inverse it? Or should I get another icon from QStyle?
This question (and several others) are from the intention of creating a chrome like tab in PyQt application, by hiding the titlebar and reimplementing control box. But it didn't gives the best result. Right now this is my solution to create a chrome like tab in PyQt application. Therefore, I close this question.

QTableView Zoom In/Out

I'm trying to create a QTableView that can be zoomed in and out like in Excel.
A similar question was asked here: Zooming function on a QWidget
However, I'm subclassing the QTableView in PyQt and not C so reimplementing the entire PaintEvent method is a bit evolved. The source code for that is a bit complex: https://qt.gitorious.org/qt/tiittane-qt/source/bdd4a9149789f60974603e1f7621d51378f0a108:src/gui/itemviews/qtableview.cpp#L1282
I'm looking to see if there are any other viable options to have a zoom able TableView. My first attempt was by setting the font size then realized each column and row widths would have to scale as well which can become slow. Then realized changing the font would change the print. It didn't seems like an elegant solution. Changing the scale of the painter before painting seems like the more elegant solution but would have to re-implement and translate quite a bit of code to python to do so. I'm wondering if there are any other hooks to get this done.
Thanks
If you can use QTableWidget instead then you can create a QGraphicsScene and add it to that. Then you easily control the scale of the widget within.
If you want vertical and horizontal headers always visible I think you will have to turn off the table's scrollbars (which would end up zoomed, probably not what you want anyways) and have the scrollbars part of the panel that contains the graphics scene (probably panel would be a QAbstractScrollArea with 4 cells in layout: one cell for scene, one for horiz scrollbar, one for vert scrollbar, and one for the corner maybe empty), and connect them to the table's scroll behavior.
There is no built-in method to zoom on a view.
The simplest way to separate the size of the font on the screen, versus the size of the font saved or printed, is to basically have two fonts. One to be displayed on the screen you can call 'zoom', versus the other to be saved/printed and call that 'font size'.
Note this answer is cut and pasted from the same question:
Zooming a view in PyQt?

Advanced Flex custom components for working with graphics and text

I'm looking for a new, modern components with enhanced functionality for working with graphics and text.
For example by mouse over to the text appears a icon click on that appears a panel into which you can change the font, font size, font color, letter-range, etc.
With graphics by pointing resizing handles appear, rotation, reflection, etc.
It sounds like you want to create a custom tooltip, that has the options to change/edit the appearance of the UIComponent that was hovered over. This is a tricky mofo of a component to make. I made a custom tooltip based on a Canvas, that has an item renderer associated with it. If your in earnest, I could probably put together a usable example and post it (on my blog or something).
If you hover over a component, a regular toolip appears, but when you hover over the tooltip, it expands out to a custom tooltip. I used Timer objects with event listeners added.
After that, you'll need to do all the transform stuff. Probably out of the scope of a single StackOverflow question to be honest.

Resources