PyQt - Radio button selection

688 views
Skip to first unread message

yann19

unread,
Jul 17, 2018, 1:07:51 PM7/17/18
to Python Programming for Autodesk Maya
Hi all, 

I apologize in advance that my code isn't directly related to maya.
I have created 4 radio buttons, where 2 of each buttons are created and sorted into 2 different layouts.
Only 1 radio button will be checked in each layout.

My code is as follows:
       
        time_first_hbox = QtGui.QHBoxLayout()
        start_rbtn
= QtGui.QRadioButton("Start")
        min_rbtn
= QtGui.QRadioButton("Min")
        min_rbtn
.setChecked(True)
        time_first_hbox
.addWidget(start_rbtn)
        time_first_hbox
.addWidget(min_rbtn)
   
        time_last_hbox
= QtGui.QHBoxLayout()
        end_rbtn
= QtGui.QRadioButton("End")
        max_rbtn
= QtGui.QRadioButton("Max")
        max_rbtn
.setChecked(True)
        time_last_hbox
.addWidget(end_rbtn)
        time_last_hbox
.addWidget(max_rbtn)
   
        options_time_hbox
= QtGui.QHBoxLayout()
        options_time_hbox
.addLayout(time_first_hbox)
        options_time_hbox
.addLayout(time_last_hbox)


While both the `Min` and `Max` buttons are set to checked as default, when I tried to select `End` button, instead of the default `Max` selection moved to `End`, it was `Min` that was moved.
As a result, the (user) selection is only limited to `Start/ Min/ End`  while `Max` will always be checked..

I had thought that if I had created 2 different layouts, the radio buttons selection will be limited to those within the layout (Start/Min) and (End/Max).
Am I missing something here?

yann19

unread,
Jul 17, 2018, 1:13:14 PM7/17/18
to Python Programming for Autodesk Maya
I would also like to add on that (unable to edit the post), if I clicked on the option - "Max", it will gets unchecked, and only 1 radio button selection can only be made thereafter.. 

Marcus Ottosson

unread,
Jul 17, 2018, 1:21:02 PM7/17/18
to python_in...@googlegroups.com

See http://doc.qt.io/qt-5/qradiobutton.html#details

Radio buttons are autoExclusive by default. If auto-exclusive is enabled, radio buttons that belong to the same parent widget behave as if they were part of the same exclusive button group. If you need multiple exclusive button groups for radio buttons that belong to the same parent widget, put them into a QButtonGroup.

Looks like you’ll need two “groups”.


On 17 July 2018 at 18:13, yann19 <yang...@gmail.com> wrote:
I would also like to add on that (unable to edit the post), if I clicked on the option - "Max", it will gets unchecked, and only 1 radio button selection can only be made thereafter.. 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ed1782d9-0dc5-4dbb-9d31-45d6ad48872f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Jul 17, 2018, 1:21:42 PM7/17/18
to python_in...@googlegroups.com
Alternatively, instead of two layouts, parent them to two widgets, each with their own layout, and put the two widgets in a third layout.

On 17 July 2018 at 18:20, Marcus Ottosson <konstr...@gmail.com> wrote:

See http://doc.qt.io/qt-5/qradiobutton.html#details

Radio buttons are autoExclusive by default. If auto-exclusive is enabled, radio buttons that belong to the same parent widget behave as if they were part of the same exclusive button group. If you need multiple exclusive button groups for radio buttons that belong to the same parent widget, put them into a QButtonGroup.

Looks like you’ll need two “groups”.

On 17 July 2018 at 18:13, yann19 <yang...@gmail.com> wrote:
I would also like to add on that (unable to edit the post), if I clicked on the option - "Max", it will gets unchecked, and only 1 radio button selection can only be made thereafter.. 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

Justin Israel

unread,
Jul 17, 2018, 3:50:17 PM7/17/18
to python_in...@googlegroups.com


On Wed, Jul 18, 2018, 5:21 AM Marcus Ottosson <konstr...@gmail.com> wrote:
Alternatively, instead of two layouts, parent them to two widgets, each with their own layout, and put the two widgets in a third layout.

I like your suggestion of using QButtonGroup as opposed to managing it by layout and parent. A group is more explicit about the logic and is the way I always go. 


On 17 July 2018 at 18:20, Marcus Ottosson <konstr...@gmail.com> wrote:

See http://doc.qt.io/qt-5/qradiobutton.html#details

Radio buttons are autoExclusive by default. If auto-exclusive is enabled, radio buttons that belong to the same parent widget behave as if they were part of the same exclusive button group. If you need multiple exclusive button groups for radio buttons that belong to the same parent widget, put them into a QButtonGroup.

Looks like you’ll need two “groups”.

On 17 July 2018 at 18:13, yann19 <yang...@gmail.com> wrote:
I would also like to add on that (unable to edit the post), if I clicked on the option - "Max", it will gets unchecked, and only 1 radio button selection can only be made thereafter.. 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODzwGdymXZVfKeOdu0o0cLvmRTGGS7NvSvrQF%2BYF3rfTg%40mail.gmail.com.

yann19

unread,
Jul 19, 2018, 5:50:40 PM7/19/18
to Python Programming for Autodesk Maya
Got it, thanks guys!


On Tuesday, July 17, 2018 at 12:50:17 PM UTC-7, Justin Israel wrote:


On Wed, Jul 18, 2018, 5:21 AM Marcus Ottosson <konstr...@gmail.com> wrote:
Alternatively, instead of two layouts, parent them to two widgets, each with their own layout, and put the two widgets in a third layout.

I like your suggestion of using QButtonGroup as opposed to managing it by layout and parent. A group is more explicit about the logic and is the way I always go. 

On 17 July 2018 at 18:20, Marcus Ottosson <konstr...@gmail.com> wrote:

See http://doc.qt.io/qt-5/qradiobutton.html#details

Radio buttons are autoExclusive by default. If auto-exclusive is enabled, radio buttons that belong to the same parent widget behave as if they were part of the same exclusive button group. If you need multiple exclusive button groups for radio buttons that belong to the same parent widget, put them into a QButtonGroup.

Looks like you’ll need two “groups”.

On 17 July 2018 at 18:13, yann19 <yang...@gmail.com> wrote:
I would also like to add on that (unable to edit the post), if I clicked on the option - "Max", it will gets unchecked, and only 1 radio button selection can only be made thereafter.. 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages