how to create an editable combo box
-
I want to create a combo box which has some default value ( for example my default are 4000,5000,6000) , (my range is between 4000 - 5000 ) and user should be able to insert any value in between these . Whether it can be done ?
@ManiRon
comboboxes are editable -
I want to create a combo box which has some default value ( for example my default are 4000,5000,6000) , (my range is between 4000 - 5000 ) and user should be able to insert any value in between these . Whether it can be done ?
-
@ManiRon
comboboxes are editable -
@ManiRon I used combo box set editable to true. but how to make it accept data within that range
-
@aha_1980 said in how to create an editable combo box:
By setting a Validator
any sample if possible sir ?
@ManiRon The internet is full of examples. From your description, you could probably use https://doc.qt.io/qt-5/qintvalidator.html
-
@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.
-
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.
-
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.
-
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 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.
-
@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.