I need a widget from QComboBox
, user can select item from popup or input directly in the linedit, but how to prevent the inputs out of range of the items in QComboBox? or can the text input in the lineedit always be legal?
Thanks
Asked
Active
Viewed 2,548 times
0

zhangailin
- 926
- 2
- 10
- 20
1 Answers
2
Refer to the QComboBox::setValidator(const QValidator*)
member function:
http://qt-project.org/doc/qt-4.8/qcombobox.html#setValidator
This allows you to set a validator to constrain any input that users type into the line edit of the combo box.
Qt provides three validators: QIntValidator
to constrain inputs to integers within a certain range; QDoubleValidator
to constrain inputs to floating point values within a certain range and with a specified precision; and QRegExpValidator
to constrain inputs to a particular regular expression. If your validation needs are more complex, you may also subclass QValidator
and write your own and then install it into the combo box. See also: http://qt-project.org/doc/qt-4.8/qvalidator.html

RA.
- 7,542
- 1
- 34
- 35
-
Thanks! Exactly what I want! – zhangailin Mar 13 '13 at 04:46