Solved disable QRadioButtons by QComboBox choice
-
@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 ?
-
@gnngnn said in disable QRadioButtons by QComboBox choice:
self.connect(BatchShotsFoundedTypecmb,
try
self.connect(self.BatchShotsFoundedTypecmb, QtCore.SIGNAL("currentTextChanged(const QString&)"), self.BatchShotsFoundedTypecmbEnable) -
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 ?
-
Hello SGaist,
I use Qt version 4.8.6 and PyQt4... why? -
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.
-
Thanks for the explaination :)
-
AFAIK, using the new connection style you should have something like:
self.BatchShotsFoundedTypecmb.currentIndexChanged['QString'].connect(self.BatchShotsFoundedTypecmbEnable)
-
This post is deleted! -
@SGaist
Thanks you so much, it's working perctly :)