how to create an editable combo box
-
@ManiRon
comboboxes are editable -
@ManiRon The internet is full of examples. From your description, you could probably use https://doc.qt.io/qt-5/qintvalidator.html
-
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
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.