I am learning PyQt by playing with examples. In this case, I'm playing with the webbrowser example that is located at \Python26\Lib\site-packages\PyQt4\examples\activeqt\webbrowser
.
The demo does something really odd if you add one line to set the icon text property of a QAction.
Here's a code sample of the change I tried:
self.actionBack = QtGui.QAction(MainWindow)
self.actionBack.setIcon(QtGui.QIcon(":/icons/image1.xpm"))
self.actionBack.setObjectName("actionBack")
# added this line:
self.actionBack.setIconText("Back")
One time I tried it, and the entire toolbar went blank. I can't reproduce that, now I have no effect from that one line change.
What I'm trying to figure out is what to do to the QAction so that the toolbar has text on the button beside the image, or can it be done at all like this? Is there some other way to make the toolbar have some text plus an icon?
To create a menu for a PyQt5 program we need to use a QMainWindow. This type of menu is visible in many applications and shows right below the window bar. It usually has a file and edit sub menu. The top menu can be created with the method menuBar().
To create a menu, we create a menubar we call . menuBar() on the QMainWindow. We add a menu on our menu bar by calling . addMenu() , passing in the name of the menu.
Widgets are the basic building blocks for graphical user interface (GUI) applications built with Qt. Each GUI component (e.g. buttons, labels, text editors) is a widget that is placed somewhere within a user interface window, or is displayed as an independent window.
Try setting the button style on the toolbar that the actions are being added to:
self.tbNavigate.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
...
self.actionBack.setIconText("Back")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With