PDA

View Full Version : tab order and QButtonGroup and radioButton



somename
30th May 2010, 08:03
If I have buttonGroup and several radio buttons, I can set focus only to first element of radioGroup, using tab.
How to do that If i press tab, focus set to next element?

somename
30th May 2010, 08:07
I also have made this:
void Widget::keyPressEvent(QKeyEvent *keyEvent)
{
if (keyEvent->key() == Qt::Key_Tab {
focusNextChild();
keyEvent->accept();
}
}

but this does not help me

tbscope
30th May 2010, 08:21
http://doc.qt.nokia.com/4.6/qwidget.html#setTabOrder

somename
30th May 2010, 08:28
No, it does not help..
I have tryed this thing

tbscope
30th May 2010, 08:48
It's an unresolved but/request.
http://bugreports.qt.nokia.com/browse/QTBUG-131

Use the arrow keys.
Or as an alternative, provide your own button group.

somename
30th May 2010, 08:58
can i inherit from QButtonGroup and setTabOrder?

somename
30th May 2010, 09:03
I need do it, because I have widget with ButtonGroup, that consists of 5 QPushButtons with setCheckable (true);

tbscope
30th May 2010, 09:20
Suggestion:

Set auto exclusive to false on all your buttons.
Then, when you check a button, also look at the checkstate of the other 4 buttons and set them to not checked.
This is a bit of ugly work, but then you'll get the tabs to work.

Edit: the above description is what I actually meant with your own button group.
The use of tabs to set the focus to the next button is disabled at the button level itself when using auto exclusive

somename
30th May 2010, 09:25
Thanks! !

somename
30th May 2010, 09:38
Hm.. it is not working!
I write some app which show, that we can't using tab for move focus


#include <QtGui>

class Widget : public QWidget
{
public:
Widget()
{
buttons = new QPushButton[5];

QButtonGroup *buttonGroup = new QButtonGroup;
QVBoxLayout *buttonsLayout = new QVBoxLayout;
buttonGroup->setExclusive(false);
for (int i = 0; i < 5; i++) {
buttons[i].setAutoExclusive(false);
buttons[i].setCheckable(true);
buttonGroup->addButton(&buttons[i]);
buttonsLayout->addWidget(&buttons[i]);
buttons[i].setText("button#" + QString().setNum(i));
}
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addLayout(buttonsLayout);

setLayout(mainLayout);
setFixedSize(sizeHint());
};
private:
QPushButton *buttons;
};

int main(int argc, char **argv)
{
QApplication app(argc, argv);

Widget *widget = new Widget;
widget->show();

return app.exec();
};

Any ideas?

tbscope
30th May 2010, 09:47
I'll write you something, will take an hour or two. I'll need to finish something else first.

somename
30th May 2010, 09:49
Ok I am waiting

tbscope
30th May 2010, 10:49
Here you go:
http://www.qtcentre.org/wiki/index.php?title=Button_groups_with_tab_focus

somename
30th May 2010, 11:17
Thank you very much!

Its_Me
12th January 2016, 12:00
Here you go:
http://www.qtcentre.org/wiki/index.php?title=Button_groups_with_tab_focus

I have also same problem but I cant open above link...can u suggest me