Unsolved how to create an editable combo box
-
@ManiRon The internet is full of examples. From your description, you could probably use https://doc.qt.io/qt-5/qintvalidator.html
-
@aha_1980 i have a doubt sir , when should i apply this validator , cause i applied in my mainwindow constructor, its throwing error
-
There is an example with line edits here: https://wiki.qt.io/QIntValidator
It should be very similar with combo box.
cause i applied in my mainwindow constructor, its throwing error
With such imprecise error descriptions you will likely get imprecise answers.
-
@aha_1980 whether QIntValidator restricts user while entering the data itself ?
-
@aha_1980 why because after setting validator , it accepts data less than the range
-
@aha_1980 This is my code
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include"QInputMethodEvent"
#include"QIntValidator"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->comboBox->setEditable(true);
ui->comboBox->setValidator(new QIntValidator(4400, 5000, this));
ui->lineEdit->setValidator(new QIntValidator(4400, 5000, this));}
MainWindow::~MainWindow()
{
delete ui;
} -
@ManiRon There seems indeed be some problems with the lower bound. I didn't manage to input number greater than the upper limit, but for the lower limit it did not work (e.g. it allows zero).
I think the best would be to write your own validator based on QValidator in that case. That gives you full control.
-
@ManiRon
how much less ? if you only enter 3 digits, than that is an intermediate state and has to be an acceptable input.4300 for example should not be possible.
-
@J.Hilk Its accepting from 0 to 5000 sir , But not more than 5000. But i want it to accept only from the range of 4400 to 5000
-
@ManiRon
nope, just tested it.If you write anything below 4400 the entry is not added to the combobox, if you write anything in the valid range, it is added and if you try to go above the maximum it is also not added to the combobox.
AFAIK working as intended.
If you wan't to limit your textinput of the combobox, then that's a different matter and even more complicated.
-
@J.Hilk ya i will be entering the text in the combo box as i have made it editable . while entering the text only i face this issue . It accepts from 0 to 5000