![]() This signal will fire whenever the QAction is triggered (or activated). Next, we can opt to set a status tip - this text will be displayed on the status bar once we have one. Strangely for QAction the parent element is passed in as the final parameter. You must also pass in any QObject to act as the parent for the action - here we're passing self as a reference to our main window. ![]() When creating the instance we can pass a label for the action and/or an icon. To start with we create the function that will accept the signal from the QAction so we can see if it is working. In the code below you can see this first QAction added.īutton_action = QAction("Your button", self)īutton_tStatusTip("This is your button")īutton_(self.onMyToolBarButtonClick) Each QAction has names, status messages, icons and signals that you can connect to (and much more). But with QAction you can define a single QAction, defining the triggered action, and then add this action to both the menu and the toolbar. Without QAction you would have to define this in multiple places. For example, it is common to have functions that are represented in the toolbar but also the menu - think of something like Edit->Cut which is present both in the Edit menu but also on the toolbar as a pair of scissors, and also through the keyboard shortcut Ctrl-X ( Cmd-X on Mac). What this means in English, is that you can define multiple interface elements within a single object, unified by the effect that interacting with that element has. QAction is a class that provides a way to describe abstract user interfaces. We could just add a QButton widget, but there is a better approach in Qt that gets you some additional features - and that is via QAction. We should make the toolbar a bit more interesting. So as a general rule you want to either keep one toolbar un-removeable, or provide an alternative interface in the menus to turn toolbars on and off. How can I get my toolbar back!? Unfortunately once you remove a toolbar there is now no place to right click to re-add it. Right click and click the name to toggle it off. Run it! You'll see a thin grey bar at the top of the window.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |