Results 1 to 8 of 8

Thread: QActionGroup question

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QActionGroup question

    Hi gusy,

    I have 10 action and I have added them to a QActionGroup. Only one action can be active at time and it's ok, but I need the case when any of the actions is active. But I can't do it. Is is possible to set some settings for QActionGroup so any or only one action could be active an the same time?
    (one active at the same time is default setting)

    Thanks

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QActionGroup question

    actionGroup->setExclusive(true);

    Edit: forget it.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QActionGroup question

    How about setting the exclusive property to false?

  4. #4
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QActionGroup question

    If you want to group checkable actions without making them exclusive, you can turn of exclusiveness by calling setExclusive(false)
    Does this mean than I can have no active actions? I understand as I can have more than one active action in the same time, but not any.

    Will check it anyway.

    Thanks
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  5. #5
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QActionGroup question

    setExclusive->(false); enables disactivating all actions(that's what is correct), but also enables 2 or more actions to be active at the same time, and I can't have this kind of solution.

    Maverick
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QActionGroup question

    Does it mean that you want to be able to check only 0 or 1 action?

    Edit: a quick solution is to add "none" or similar action and let user select it instead.
    Last edited by jacek; 5th October 2007 at 12:21.

  7. #7
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QActionGroup question

    Yes 0 or 1.

    Thanks
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QActionGroup question

    One idea that comes to my mind is to switch between exclusive and non-exclusive group on the fly. More or less something like this:
    Qt Code:
    1. class ActionGroup : public QActionGroup
    2. {
    3. Q_OBJECT
    4. public:
    5. ActionGroup(QObject* parent = 0) : QActionGroup(parent)
    6. {
    7. setExclusive(true);
    8. connect(this, SIGNAL(hovered(QAction*)), this, SLOT(actionHovered(QAction*)));
    9. }
    10.  
    11. private slots:
    12. void actionHovered(QAction* action)
    13. {
    14. setExclusive(action != checkedAction() || !action->isChecked());
    15. }
    16. };
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. Access to QSqlTableModel::isDirty Question.
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2007, 17:49
  2. Replies: 1
    Last Post: 15th March 2007, 20:45
  3. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 15:34
  4. QThread exit()/quit() question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2006, 14:38

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.