How make a custom QPushButton in PyQt5? - python

I need to add a big button which will start some process. I know that I can make QPushButton large enough, however, I wish it be something like that
What can you suggest?

use flat QPushButton with transparent icon.

Related

How do I load QMovie within QtDesigner?

I need to be load QMovie in QtDesigner. I noticed that a lot of classes are not accessible from QtDesigner. I usually design in QtDesigner and I just load the ui file directly in my code. This way I never had to worry about implementing the GUI itself in code.
Is there a way I can do this without having to edit my code ?
So in summation I want to add QMovie to a horizontal layout in my main window.
QMovie is not a widget, so it makes no sense to add it to as layout.
You probably want a QLabel, which has a setMovie method for dispalying animated images. But note that a QMovie cannot play videos - if you want that functionality, you will have to use a Phonon.VideoWidget, rather than a QLabel.

Order of push buttons on different platforms (QDialogButtonBox)

The QDialogButtonBox widget automatically reorders it's buttons to meet the expectations of users on different platforms. I'd like to follow this behavior, but with my own button labels (e.g. 'Import' instead of 'OK'). How can I achieve this? Is it possible to use QMessageBox, or do I need to write my own implementation? I'm writing my application with PyQt4, and Qt Designer.
See screenshot below of QDialogButtonBox on OS X in Aqua and Cleanlooks styles.
QDialogButtonBox can do this for you, but you will need to create a dialog to put one in first (a trivial amount of work).
...
auto buttons = new QDialogButtonBox( this );
buttons->addButton( "Import", QDialogButtonBox::AcceptRole );
buttons->addButton( "Cancel", QDialogButtonBox::RejectRole );
...
The docs are here (it's C++, but I'm sure can follow it), the general idea is that ButtonRole is used by the current style layout to rearrange the buttons.

How to make a flat button with rich text formating with Qt4?

I would like to create flat buttons displaying rich text and images.
For instance a button should be able to display:
|¯¯¯¯¯¯| Title of Button ¯¯¯¯|
| ICON | Description of button |
|_____̣̣_|___________________|
I've been playing around with Qt4 and I couldn't find an easy way to produce such a button. Adding a QLabel as a child of a QPushButton does not work properly (the text is not aligned properly and the button does not respect the size of the label's content).
Is there a way to produce a simple flat button that can handle rich text and images as its content? Can I create a button from a QLabel perhaps?
If you look at the documentation, you can see that QPushButton doesn't accept child widgets.
So you will have to write your own widget. QLabel is a good start. Give it the same border and color that a QButton would get (the documentation of the flat property of the QPushButton should help).
And you'll need to implement mousePressEvent plus add the necessary button slots. A good idea is probably to look into the source code of QAbstractButton to see how it's implemented.

PyQt Hide QDialogs Inside of QTreeWidget

I have a QTreeWidget with QComboBoxes inside of it. I would like to be able to hide the combo boxes.
I am getting the QComboBox out of the tree using the itemWidget function. I have tried using setVisible(False) and hide() but neither work. Can anyone explain why this is the case and possibly offer a soultion?
I suspect it has something to do with the QTreeWidget or the QTreeWidgetItems controlling the visibility of its widgets.
Have you tried putting the QComboBoxes inside a layout inside a QWidget, and placing the QWidget in the QTreeWidget?

Pyqt tabs like in Google Chrome

I would like to have my pyqt aplication have tabs in the menu bar like Google Chrome :)
Any suggestions or a simple example on how to do it?
I did find these relevant link:
- http://ivan.fomentgroup.org/blog/2009/03/29/instant-chrome/
You have to use the Qt.FramelessWindowHint for that, and then create your own Max, Min, Close buttons as Widgets and add them there. I have a good working toolkit for these types of softwares: http://traipse.assembla.com/spaces/ghostqt
In your case you should reclass the resizeEvent so you can change the flags. If the window is maximized you will not need to worry about moving it around, but if it is not maximized you can remove the Qt.FramelessWindowHint flag and get your title bar back; just like Chrome does.
Is that what you are looking for?
If I understand correctly, just create a QWindow that contains a QTabBar widget(and not a QMenuBar, or simply use a QTabWidget as your main program widget.
you need to do the following:
remove window border (FramelessWindowHint)
Implement your own window moving and resizing code
Insert tabbar on the top, and add buttons for close etc. to it (or create a frame that will contain the tabbar and buttons)
And that's all that was done in Webbie (the link you provided) :)

Categories