Accessing combo and textbox values
I'm using Python 3 and QT4 with pyqt. I'm using Designer. I've been unable to access data from qcomboboxes and qplaintextedits.
I've read the documentation here: http://qt-project.org/doc/qt-4.8/qcombobox.html http://qt-project.org/doc/qt-4.8/qplaintextedit.html
The only thing on these pages that appears to describe how to pull the selected value are 'plainText' for the plain text box and 'currentText' for the combo box. These aren't explicitly described as the solution, but they're the only thing I found that makes sense.
They do not return errors, but both the combo boxes and text boxes return the default value I set in QT designer, regardless of what is currently selected when running the program. Any ideas?
Example code I'm using:
x = window.ui.tb_x.toPlainText()
y = window.ui.cb_y.currentText()
I've also tried
y = window.ui.cb_y.itemData(window.ui.currentIndex())
what do you expect getting from the QPlainTextEdit other than its plain text it is holding?!
For the comboBox try this:
QVariant v = window.ui.cb_y.itemData(window.ui.currentIndex(), Qt::DispalyRole);
But i'm just guessing since you haven't mentioned what you actually want to get out of these widgets?
Hi, When in designer a couple of items have been inserted in a QComboBox, the currentText() should return the QString present at that time. It does work for me, have you debugged the code? Maybe you make an error along the way ;-)
Thank you for the help. It turns out that my code was structured incorrectly for QT. I have a separate class in my program for each QT window. Functions that take input seem to only work when in this class, not in my main program body. I moved the input function to it's window's class, and changed the widget prefixes to 'self.ui'. Problem solved.
Raven: I was expecting the current value, not the default one. Ie, I set in Designer that a text box shows 'apples' initially. I run the program, change the box to 'oranges'. The program thinks the input is 'apples'.