开发者

PyQt - Radiobuttons not checkable

开发者 https://www.devze.com 2023-03-17 19:47 出处:网络
I want to display the result of an SQL query with radio buttons. For this purpose, I use an array of radiobuttons. This works fine, it displays what I want. The problem I have is that the buttons are

I want to display the result of an SQL query with radio buttons. For this purpose, I use an array of radiobuttons. This works fine, it displays what I want. The problem I have is that the buttons are not "checkable". If I click on them, nothing happens. I'm sure it is a stupid mistake, but I can't see what's wrong.

Here is my code :

groups = select.getGroups(self.parent.db) #This returns a list of strings
self.groupList = {}
self.groupBtn = []
i = 0
radioLayout = QtGui.QVBoxLayout开发者_JAVA百科()
radioGroup = QtGui.QGroupBox()
for g in groups:
      self.groupList[g[0]] = i
      name = g[0]
      self.groupBtn.append(QtGui.QRadioButton(name))
      radioLayout.addWidget(self.groupBtn[i])
      i = i+1

radioGroup.setLayout(radioLayout)
self.groupBtn[0].setChecked(True)
self.groupLayout.addWidget(radioGroup)

Is there something obvious I'm missing ?


  1. "Radio buttons typically present the user with a "one of many" choice. In a group of radio buttons only one radio button at a time can be checked; if the user selects another button, the previously selected button is switched off."

  2. If that is not your desired behaviour, you may consider using check buttons (QCheckButton). If it is:

  3. You need to be sure that you have not incidentally set setAutoExclusive(false) somewhere in code, for any of those radio buttons (by default it is set on true).

  4. Last thing I can suggest (based on the code that you have shown): Try to put radio buttons in QButtonGroup() instead of QGroupBox().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号