Results 1 to 3 of 3

Thread: QAction inside QWidget

  1. #1
    Join Date
    Apr 2013
    Posts
    63
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default QAction inside QWidget

    I have Checkable actions added to a menu. I would like a replica of that menu permanently displayed in a QWidget. I am looking for a way to add a checkable action in menu and a widget so that they ate syncronized.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QAction inside QWidget

    There is not ready made widget to do so. You will have write you own widget and connect the signal and slots both ways to keep the menu action and widget in sync. Take special care not to connect the signals in a recursive manner.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    Default Re: QAction inside QWidget

    Quote Originally Posted by Santosh Reddy View Post
    Take special care not to connect the signals in a recursive manner.
    That shouldn't be a problem if the slots check current state vs. new state before doing an emit.

    E.g. if you go for a QCheckBox as the in-widget visualization, then it should be save to connecti QCheckBox::toggled() to QAction::setChecked() and QAction::toggled() to QCheckBox::setChecked()

    Both setChecked() slots will only emit toggled() if the value passed to them is different to the one the object currently has.

    Cheers,
    _

Similar Threads

  1. QWidget inside MFC project
    By hINTModuleState in forum Newbie
    Replies: 3
    Last Post: 9th October 2015, 15:22
  2. QToolbar inside QWidget
    By theprobe in forum Qt Programming
    Replies: 1
    Last Post: 14th February 2011, 16:53
  3. Convert from QAction to QWidget
    By duck182 in forum Qt Programming
    Replies: 11
    Last Post: 26th January 2011, 15:25
  4. Why QAction inside Qmenu doesn't display Icon ?
    By jpujolf in forum Qt Programming
    Replies: 8
    Last Post: 21st December 2009, 12:51
  5. how to add QMenu or QAction inside QDesigner
    By eric_vi in forum Qt Tools
    Replies: 1
    Last Post: 2nd August 2009, 16:48

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.