Results 1 to 7 of 7

Thread: QButtonGroup keyboard navigation

  1. #1
    Join Date
    Mar 2012
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QButtonGroup keyboard navigation

    Hello,

    i stumbled on a problem using QButtonGroups. As far as I understand QButtonGroup logically organises AbstractButtons. A TAB would navigate on the group and the next TAB navigate away from the group. Within the group the AbstractButtons are navigated with the arrow keys. This all works fine with QRadioButtons. I need the same concept but with QCheckBoxes...but as soon as my ButtonGroup consists of CheckBoxes the arrow key navigation does't work any more (TAB navigation is as aspected). I also checked for checkable QPushButton - same problem here. For CheckBox and PushButton it is practically not possible to navigate through the Buttons of the group anymore (apart from the mouse).

    Please consider the following code, change BUTTON_TYPE as neccessary:

    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3.  
    4. #define BUTTON_TYPE 0
    5.  
    6. int main(int argc, char **args)
    7. {
    8. QApplication dialog(argc, args);
    9.  
    10. QWidget window;
    11.  
    12. QButtonGroup* bg = new QButtonGroup(&window);
    13.  
    14. switch(BUTTON_TYPE)
    15. {
    16. case 0:
    17.  
    18. cb1 = new QCheckBox("cb1", &window);
    19. cb2 = new QCheckBox("cb2", &window);
    20. cb3 = new QCheckBox("cb3", &window);
    21. break;
    22. case 1:
    23. cb1 = new QPushButton("cb1", &window);
    24. cb2 = new QPushButton("cb2", &window);
    25. cb3 = new QPushButton("cb3", &window);
    26. cb1->setCheckable(true);
    27. cb2->setCheckable(true);
    28. cb3->setCheckable(true);
    29. break;
    30. default:
    31. cb1 = new QRadioButton("cb1", &window);
    32. cb2 = new QRadioButton("cb2", &window);
    33. cb3 = new QRadioButton("cb3", &window);
    34. break;
    35. }
    36.  
    37. bg->addButton(cb1);
    38. bg->addButton(cb2);
    39. bg->addButton(cb3);
    40.  
    41. QLayout *layout = new QVBoxLayout;
    42. layout->addWidget(cb1);
    43. layout->addWidget(cb2);
    44. layout->addWidget(cb3);
    45.  
    46. window.setLayout(layout);
    47. window.show();
    48.  
    49. return dialog.exec();
    50. }
    To copy to clipboard, switch view to plain text mode 

    I also flew over the Qt sourcecode (QAbstractButton::moveFocus), but on the rush I couldn't find any reason why it shouldn't work for the other two Button types (PushButton and Checkbox).
    Did I forget something or is there any misconception on my behalf? Anybody else noticed this problem?

    Hope you can enlighten me.

    Regards

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

    Default Re: QButtonGroup keyboard navigation

    Set QAbstractButton::setAutoExclusive(true); on all the buttons/checkboxes
    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. The following user says thank you to Santosh Reddy for this useful post:

    braindead (3rd September 2013)

  4. #3
    Join Date
    Mar 2012
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QButtonGroup keyboard navigation

    Hello,

    thanks for the hint. I thought it is enough that the ButtonGroup is Exclusive.
    However, if it is so tight tied to AutoExlusive than that concept is not usable for me...i need just a logical group w/o AutoExclusive.
    I have already implemented arrow key navigation between the group members, was just curious what the cause of the above stated problem is.

    Nonetheless, I think it is not cleanly programmed in Qt source. You should never get stuck in a situation where you can't operate the UI anymore. But this is just my opinion.

    Thanky again.

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

    Default Re: QButtonGroup keyboard navigation

    I see this as nice feature. Image a scenario where you have mulitple buttons in a group, and only few of them are exclusive.

    Having exclusive setting on both group and button is more flexible solution.
    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.

  6. #5
    Join Date
    Mar 2012
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QButtonGroup keyboard navigation

    Yes, but those buttons that are not exclusive can never be reached using the keyboard...not with Arrow keys, not with TAB, not with any other key. So I am dependent on using the mouse. I think navigation should at least somehow work.

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

    Default Re: QButtonGroup keyboard navigation

    Yes I agree. Tab should work inside a QButtonGroup with non-exclusivve buttons. May be you can take this issue up with Qt Bugs.
    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.

  8. #7
    Join Date
    Mar 2012
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QButtonGroup keyboard navigation

    Santosh,

    I played around a little bit with above sample code. Found out the following:

    1) buttonGroup exclusive/ containing AbstractButtons autoexclusive: -> real autoexclusive behaviour, navigation per arrows possible

    2) buttonGroup not exclusive/ containing AbstractButtons autoexclusive -> multiple checks allowed, navigation per arrows possible ( -> just what I need)

    3) buttonGroup exclusive/ containing AbstractButtons not autoexclusive -> only check/uncheck of the first/focused button, no navigaton possible

    4) buttonGroup not exclusive/ containing AbstractButtons not autoexclusive -> only check/uncheck of the first/focused button, no navigaton possible

    Navigation seems only to be possible when the AbstractButtons are autoexclusive. However the autoexclusive behavriour is overruled by the exclusive property of the buttonGroup.

    You are right this seems to be a case for Qt Bugs. And maybe the documentation could be a little bit more clear about the mutual influence.

    Thanks

Similar Threads

  1. Can't add QButtonGroup to QGridLayout
    By migel in forum Newbie
    Replies: 1
    Last Post: 27th June 2011, 17:27
  2. Replies: 1
    Last Post: 20th April 2011, 21:51
  3. TreeView keyboard navigation
    By Onanymous in forum Newbie
    Replies: 2
    Last Post: 14th May 2010, 06:22
  4. How to add QButtongroup to Layout?
    By pospiech in forum Qt Programming
    Replies: 1
    Last Post: 27th April 2008, 13:22
  5. QButtonGroup usage?
    By Caius Aérobus in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2008, 07: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
  •  
Qt is a trademark of The Qt Company.