disable QRadioButtons by QComboBox choice
-
Hello,
Did someone know how to disable or enable QRadioButtons when QComboBox selection is changed?#self.MyQComboBox .clicked.connect(self.MyQComboBoxFunction)
def MyQComboBoxFunction(self, *args):
TypeChoice = str(self.MyQComboBox .currentText())
if TypeChoice == 'LGT': MyQRadioButtons1.setEnabled(false)
if TypeChoice == 'ANM': MyQRadioButtons2.setEnabled(true)Thoses lines aren't working....any ideas?
by advance, thanks! -
Hi,
Your connect statement being commented, your slot is likely not getting called. Otherwise, you are modifying two different radio button with your if statements so it's also not clear what you are expecting.
-
that's true, sorry,
BatchType = ['LGT','ANM'] for eachBatchType in BatchType: self.MyQComboBox .addItem(eachBatchType) self.MyQComboBox.clicked.connect(self.MyQComboBoxFunction) def MyQComboBoxFunction(self, *args): TypeChoice = str(self.MyQComboBox .currentText()) if TypeChoice == 'LGT' : MyQRadioButtons1.setEnabled(false)
-
Did you check whether the slot is being called ? That the connection was successful ?
-
@SGaist said in disable QRadioButtons by QComboBox choice:
Did you check whether the slot is being called ? That the connection was successful ?
If it is so.
@gnngnn
https://stackoverflow.com/questions/3965093/pyqt-or-just-qt-how-to-get-qcombobox-to-fire-a-signal-whenever-it-is-set-to-a
Look up -
Thanks a lot for your answers, so I'd tryed to change this line:
self.MyQComboBox.clicked.connect(self.MyQComboBoxFunction)
with this:
self.connect(BatchShotsFoundedTypecmb, QtCore.SIGNAL("currentTextChanged(const QString&)"), self.BatchShotsFoundedTypecmbEnable)
teh result is:
global name 'BatchShotsFoundedTypecmb' is not defined
but this line isn' defined it?:self.MyQComboBox .addItem(eachBatchType)
-
Can you share the full code of your python class ?
-
-
here is a more complete version of the UI,
def getWindow(): ptr = mui.MQtUtil.mainWindow() return sip.wrapinstance(long(ptr), QtCore.QObject) uiFile = os.path.join(os.path.dirname(__file__), 'Gui/ProjectManager.ui') form_class, base_class = uic.loadUiType(uiFile) class ProjectManager(base_class, form_class): def __init__(self, parent = getWindow()): super(base_class, self).__init__(parent) self.setupUi(self) BatchType = ['LGT','ANM'] for eachBatchType in BatchType: self.MyQComboBox .addItem(eachBatchType) self.connect(self.BatchShotsFoundedTypecmb, QtCore.SIGNAL("currentTextChanged(const QString&)"), self.BatchShotsFoundedTypecmbEnable) self.BatchShotsFoundedTypecmb.currentTextChanged.connect(self.BatchShotsFoundedTypecmbEnable) self.show() def MyQComboBoxFunction(self, *args): TypeChoice = str(self.MyQComboBox .currentText()) if TypeChoice == 'LGT' : MyQRadioButtons1.setEnabled(false)
now the error is: 'QComboBox' object has no attribute 'currentTextChanged'
i don't understand why? -
What version of Qt and PyQt are you using ?
-
Because it's the kind of details that are important. For example you are using an outdated version of Qt (latest Qt 4 release is 4.8.7) from a series that has reached EOL.
The current Qt version is 5.9.0 with 5.9.1 pointing at the corner.
So if you are starting a new project and unless you're locked to that precise version of Qt, you should rather use something a bit more recent.
Qt 5 is mostly compatible with some breaks here and there, so again, it's good to know what we deal with. Like also the version of PyQt4 that you are using.
-
AFAIK, using the new connection style you should have something like:
self.BatchShotsFoundedTypecmb.currentIndexChanged['QString'].connect(self.BatchShotsFoundedTypecmbEnable)