Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7038435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:40:08+00:00 2026-05-28T01:40:08+00:00

In this sample of code: from PyQt4.QtGui import QDialog, QPushButton, QRadioButton, QHBoxLayout, QApplication, QButtonGroup

  • 0

In this sample of code:

from PyQt4.QtGui import QDialog, QPushButton, QRadioButton, QHBoxLayout, QApplication, QButtonGroup
import sys

class Form(QDialog):
    def __init__(self, parent=None):
        super(Form, self).__init__(parent=None)

        button = QPushButton('Button')
        self.radiobutton1 = QRadioButton('1')
        self.radiobutton2 = QRadioButton('2')
        #self.group = QButtonGroup()
        #self.group.addButton(self.radiobutton1)
        #self.group.addButton(self.radiobutton2)       
        #self.group.setExclusive(False)

        layout = QHBoxLayout()
        layout.addWidget(button)
        layout.addWidget(self.radiobutton1)
        layout.addWidget(self.radiobutton2)
        self.setLayout(layout)

        button.clicked.connect(self.my_method)

    def my_method(self):
        self.radiobutton1.setChecked(False)
        self.radiobutton2.setChecked(False)

app = QApplication(sys.argv)
form = Form()
form.show()
app.exec_()

When the button clicked I expect the selected radioButton to be unchecked, but that never happens. If I uncomment the comment lines and run the code, then I can uncheck radioButtons. But another problem occurs. Because the group is not exclusive, I can set both radioButtons checked something that must not happens.

What should I do to be able to unckeck the buttons while only one button at a time can be selected?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:40:09+00:00Added an answer on May 28, 2026 at 1:40 am

    This feels like cheating, but it works:

    import sys
    import PyQt4.QtGui as QtGui
    
    class Form(QtGui.QDialog):
        def __init__(self, parent=None):
            super(Form, self).__init__(parent)
    
            button = QtGui.QPushButton('Button')
            button.clicked.connect(self.my_method)
    
            self.radiobutton1 = QtGui.QRadioButton('1')
            self.radiobutton2 = QtGui.QRadioButton('2')
    
            layout = QtGui.QHBoxLayout()
            layout.addWidget(button)
            layout.addWidget(self.radiobutton1)
            layout.addWidget(self.radiobutton2)
            self.setLayout(layout)
    
            self.group = QtGui.QButtonGroup()
            self.group.addButton(self.radiobutton1)
            self.group.addButton(self.radiobutton2)       
    
        def my_method(self):
            self.group.setExclusive(False)        
            self.radiobutton1.setChecked(False)
            self.radiobutton2.setChecked(False)
            self.group.setExclusive(True)
    
    app = QtGui.QApplication(sys.argv)
    form = Form()
    form.show()
    app.exec_()
    

    As you’ve pointed out, when self.group.setExclusive(False) is set, you can untoggle both radio buttons.

    And when self.group.setExclusive(True), only one radio button can be set.

    So my_method simply calls self.group.setExclusive(False) so it can unset both radio buttons, then resets self.group.setExclusive(True).


    PS. I think parent should not be set to None on this line:

    super(Form, self).__init__(parent = None)
    

    since if a non-trivial parent is sent to Form, you would probably want to pass that parent on to QDialog.__init__.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this sample of code: import sys from PyQt4.QtGui import (QApplication, QHBoxLayout, QVBoxLayout,
I have this sample of code: import sys import time from PyQt4.QtGui import *
I have this sample code for async operations (copied from the interwebs) public class
this is a sample code from delete function in my LinkedList class which deletes
Another jquery calculation question. I've this, which is sample code from the plugin site
In the below code sample, what does {0:X2} mean? This is from the reflection
Consider this sample code: <div class=containter id=ControlGroupDiv> <input onbeforeupdate=alert('bingo 0'); return false; onclick=alert('click 0');return
Given this sample code: #include <iostream> #include <stdexcept> class my_exception_t : std::exception { public:
I'm trying to use this sample code from Microsoft to determine what encoder options
This is from some sample code from a book // On launch, create a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.