Results 1 to 14 of 14

Thread: QAction with QPushButton

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    101
    Thanked 15 Times in 15 Posts

    Default Re: QAction with QPushButton

    I find the concept of QActions very appealing in terms of defining all action related things like text, icon, tool tip, checkable, keyboard shortcut and what not in one place, pointing it to the slot that is to be triggered, and then attaching the action to a button or a menu. But apparently this concept has not been thoroughly implemented and the suggestions made in this thread so far are redirections to the parts of the framework that work well together with QAction.

    Obviously, QPushButtons ignore an attached QAction altogether. This fact is what started this thread in the first place. The suggestion to connect a QPushButton to a QAction and then the QAction to a slot makes the QAction an obsolete link in the chain according to my sense of simplicity. Perhaps it makes more sense in a mixed scenario, where QPushButtons, QToolButtons and QMenus are used in combination, but even then, the QPushButton would stick out of the pattern, because you would have to manually set up things for them that you already defined in the QAction. I wonder how a QPushButton supporting a QAction (for example by at least triggering it), would impair its general purpose applicability in any way.

    Quote Originally Posted by anda_skoa View Post
    Ranting about a proposed solution without even trying, trying something totally unrelated instead and ranting about that and all based on a question you didn't even want an answer for.
    You are jumping to uninformed conclusions here. I have tried the QToolButton suggestion even before I made my second post in this thread. Yes, the QToolButton seems to be the only object that actually does the job of supporting QActions all the way. At least I have tested the tool tip and the checkable feature and whether it triggers the attached action or not. But adding a QToolButton to a QMenuBar clashes with QMenus and QActions added to the QMenuBar, because QToolButtons are widgets that would like to be inside a layout, while QMenus and QActions do their own thing automatically. So either you introduce an additional QToolBar with a layout to add your QToolButtons to, or you design some kind of layout hack that allows for QToolButtons to coexist with QMenus and QActions in a QMenuBar in some magic way. I didn't elaborate on it in this detail in my second post, since I focused on the wonderful possibility of adding QActions to a QMenuBar without ever defining a button, a layout, or even an additional tool bar. I wonder if I managed to convey the idea of this "totally unrelated" approach more clearly this time.

    Now, as it turns out, QActions in QMenuBars do not show the tool tip, nor do they render a visual feedback of checkability.

    Quote Originally Posted by ChrisW67 View Post
    Checkable does work with an action in the QMenuBar. The QAction is marked checked and any QToolButton or QMenu items attached to that action are rendered "checked" when the item in the QMenuBar is clicked. The QMenuBar does not expect a menu to be on/off and consequently does not render a distinct "checked" look.
    I understand that a QMenu in a QMenuBar does not need to be checkable, but a QAction in a QMenuBar is an entirely different thing. I don't see why it shouldn't be possible to visually support checkable and to show a tool tip in this case. Yes, QActions inside QMenus do support the checkable feature, but they also don't show the tool tip. And as tool tips and checkability are advertised parts of the QAction concept, I found these flaws disappointing.

    Quote Originally Posted by ChrisW67 View Post
    QPushButton and QToolButton are both QAbstractButtons [...] QMenuBar and QMenu is a hierarchical presentation of QActions [...] The range of options represents the range of common UI widgets on the various platforms Qt started on.
    While QToolBar and QToolButton, QPushButton, and QMenu and QMenuBar may have a slightly different purpose in UI widgets, their functionality is essentially the same. You click on them and you trigger an action. My "ranting" is an attempt to make the point that all these objects could support QAction in a unified way by implementing all the features (tool tip, checkable etc.) that are promised by its interface and documentation.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: QAction with QPushButton

    It's an open source project. If you want to change its behaviour then sign up, propose and gain agreement for the changes, write and submit them. Complaining about it endlessly here will not change anything. Fighting for changes that are visually different from the native UI look/guidelines for the respective platforms will be an uphill battle: tool tips on menu items being the obvious case in point.

  3. The following user says thank you to ChrisW67 for this useful post:

    anda_skoa (29th January 2014)

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: QAction with QPushButton

    Quote Originally Posted by Cruz View Post
    Obviously, QPushButtons ignore an attached QAction altogether.
    No. They just don't have any override implementation for actions, i.e. they treat QAction like any other widget.

    Quote Originally Posted by Cruz View Post
    I wonder how a QPushButton supporting a QAction (for example by at least triggering it), would impair its general purpose applicability in any way.
    I don't think it would. Have you tried?

    Quote Originally Posted by Cruz View Post
    You are jumping to uninformed conclusions here.
    Obviously I was jumping to a conclusion since there was strange change in topic. And of course it was uninformed since you did not provide any information.

    The original scenario was triggering an action through a QPushButton.
    And, given your insistence that it was always about menu bar: how did you add the QPushButton into the menu bar that does not work for the QToolButton?

    Quote Originally Posted by Cruz View Post
    So either you introduce an additional QToolBar with a layout to add your QToolButtons to
    Whatever worked for your QPushButton should also work for a QToolButton.

    Quote Originally Posted by Cruz View Post
    Now, as it turns out, QActions in QMenuBars do not show the tool tip, nor do they render a visual feedback of checkability.
    Have you checked if it is a style issue? Do non-Qt applications on the platform show tooltips or checkmarks in the menu bar?

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 22nd February 2010, 09:30
  2. How can i get QAction or QPushButton name
    By duduqq in forum Qt Programming
    Replies: 5
    Last Post: 30th July 2008, 05:09
  3. QPushButton QMenu QAction
    By hgedek in forum Newbie
    Replies: 2
    Last Post: 1st November 2007, 12:29
  4. Replies: 3
    Last Post: 26th September 2006, 12:16
  5. QAction
    By mickey in forum Qt Programming
    Replies: 7
    Last Post: 17th July 2006, 09:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.