[Qt-interest] QRadioButton setDown(true) initialise problem.
phil prentice
philp.cheer at talktalk.net
Fri Jan 8 11:59:29 CET 2010
Thanks Mike
Unfortunately I mis-interpreted the QT documentation in that I thought it said
that the default value for the checked property was false...so thought that I
could not use setChecked(). Thanks for that.
I had tryed setChecked() in my original code, and it did'nt seem to work at
all. However I now fully understand that that was for a completely different
reason(bug)!!
I really appreciate your help
Thanks
Phil
On Thursday 07 January 2010 19:27, Mike Davis wrote:
> Try setChecked(true) instead. Since both radio buttons are children of
> the top widget, they are exclusive to each other and you shouldn't
> observe any odd behavior. If you need multiple sets of exclusive radio
> button groups on the same widget, you can use a QButtonGroup like this.
>
> #include <QApplication>
> #include <QtGui>
>
> int main(int argc, char *argv[])
> {
> QApplication app(argc,argv);
> QWidget *main = new QWidget;
> QVBoxLayout *lyt = new QVBoxLayout;
> QButtonGroup *grp = new QButtonGroup;
> QButtonGroup *grp2 = new QButtonGroup;
> QRadioButton *q1 = new QRadioButton("Grp 1 Btn 1");
> QRadioButton *q2 = new QRadioButton("Grp 1 Btn 2");
> QRadioButton *q3 = new QRadioButton("Grp 2 Btn 1");
> QRadioButton *q4 = new QRadioButton("Grp 2 Btn 2");
>
> //Add buttons to group 1
> grp->addButton(q1);
> grp->addButton(q2);
>
> //Add buttons to group 2
> grp2->addButton(q3);
> grp2->addButton(q4);
>
> //Add buttons to layout
> lyt->addWidget(q1);
> lyt->addWidget(q2);
> lyt->addWidget(q3);
> lyt->addWidget(q4);
>
> //Set layout, set state
> main->setLayout(lyt);
> q1->setChecked(true);
> main->show();
> return app.exec();
> }
>
>
> Mike Davis
>
> On 1/7/2010 9:04 AM, phil prentice wrote:
> > Hi
> > I have an application where I need to initialise a radiobuttons state
> > at startup. If I create the button and then set down to true, when I go
> > and select other radiobuttons using the mouse (buttons have same
> > parent)the radio button that I originally pressed down via setDown() will
> > remain down until I use the mouse to select it then all the buttons work
> > fine(exclusively) as expected.
> >
> > Heres a bit of code to demonstrate (although to be honest this seems to
> > have even more bizaire consequences, but thats another problem).
> >
> > #include <QApplication>
> > #include <QtGui>
> > int main(int argc, char *argv[])
> > {
> > QApplication app(argc,argv);
> > QWidget *top = new QWidget();
> > QRadioButton *q1 = new QRadioButton("button1",top);
> > QRadioButton *q2 = new QRadioButton("button2",top);
> > q1->setDown(true);
> > q2->setDown(true);
> > q1->move(5,10);
> > q2->move(5,40);
> > top->show();
> > return app.exec();
> > }
> >
> > I get some strange results when I run the above which I dont understand.
> > When I first see the displayed widget I see both radio buttons
> > down..which is wrong. However if I simply move my mouse the first button
> > is changed to being up (which is what I would have expected to see when
> > it was first displayed???).
> >
> > Anyway I now move on to my main problem which is that when I select
> > button1 with the mouse button 2 remains down. Its not until I select
> > button2 with the mouse that both buttins start behaving as they should
> > do.
> >
> > I know the above code is a bit basic, but I just wanted to demonstarte my
> > problem(s).
> > I'm using QT 4.2.1 which I appreciate is a bit out of date now, but I'm
> > sure its my understanding that is at fault here.
> > What am I doing wrong?
> > Thanks for your help.
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list