Results 1 to 5 of 5

Thread: What does QWidget.addAction() do actually?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    22
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default What does QWidget.addAction() do actually?

    Hi, I don't really understand what QWidget.addAction() does even after reading the documentation, I do the following:

    connect(action_Close, SIGNAL(triggered()), this, SLOT(close()) );
    buttonClose->addAction(action_Close);


    I figure that the above code would cause clicking buttonClose to call close() and close the window. But nothing happen, what am I doing wrong?

    The compiler output doesn't show any error about assigning the signal and slot. And close() is a SLOT in QWidget.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,004 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: What does QWidget.addAction() do actually?

    That's the wrong approach, you either use the QPushButtons clicked signal or use a action which can be triggered. addAction() adds an action to a widget and it is shown when the context menu of this widget is requested.

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

    jezz (16th September 2010)

  4. #3
    Join Date
    Aug 2010
    Posts
    22
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What does QWidget.addAction() do actually?

    Quote Originally Posted by Lykurg View Post
    That's the wrong approach, you either use the QPushButtons clicked signal or use a action which can be triggered. addAction() adds an action to a widget and it is shown when the context menu of this widget is requested.
    Thanks, but what do you mean by "action which can be triggered"? Aren't all QAction can be triggered?

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,004 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: What does QWidget.addAction() do actually?

    Quote Originally Posted by jezz View Post
    Thanks, but what do you mean by "action which can be triggered"?
    Yeah, it is missunderstandable. I meant, that if you use addAction on the widget you can't trigger the added action directly. Other example: Add an action to a QToolButton, then you can trigger that action directly by clicking the button.

  6. The following user says thank you to Lykurg for this useful post:

    jezz (16th September 2010)

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: What does QWidget.addAction() do actually?

    addAction() only associates a given action with a given widget, nothing more. Some widgets (like QToolBar) detect such associations and perform additional things then (i.e. QToolBar creates a tool button, initializes it with the action and adds it to its own layout).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    jezz (16th September 2010)

Similar Threads

  1. Promoting the parent QWidget of a QWidget form
    By extrakun in forum Qt Tools
    Replies: 6
    Last Post: 16th April 2010, 14:19
  2. Replies: 1
    Last Post: 12th April 2010, 12:55
  3. Replies: 3
    Last Post: 1st April 2010, 23:56
  4. Replies: 12
    Last Post: 21st November 2008, 04:42
  5. Replies: 1
    Last Post: 2nd May 2006, 21:11

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.