QT I want to increase the size of comboBox Down list not the drop- Down icon ?
-
I have a combo box and i want to change (increase) the size of the down list. That contain all description index value visible.
Initially I am getting this one output.But i want output like this
Also I want to remove the icon index that is showing inside the down list. Here is my code.
QIcon icon = QIcon::fromTheme("C:/Users/DragDrop/black-play-button.jpg"); QString label = ""; ui->comboBox->addItem( icon,label ); ui->comboBox->setMinimumWidth(100); ui->comboBox->setIconSize(QSize(40, 40)); ui->comboBox->setDisabled(false); ui->comboBox->addItem("Fill viewport ctrl+0"); ui->comboBox->addItem("100% ctrl+1"); ui->comboBox->addItem("200% ctrl+2"); ui->comboBox->addItem("400% ctrl+3"); ui->comboBox->addItem("800% ctrl+4");
-
Hi
You can set size via the model. (pr item)#include <QtGui>
#include <QApplication>
#include <QComboBox>int main(int argc, char **argv)
{
QApplication app(argc, argv);
QComboBox cb;
cb.addItems(QStringList() << "a" << "b" << "c" << "d");
cb.model()->setData(cb.model()->index(0, 0), QSize(100, 100), Qt::SizeHintRole);
cb.show();
return app.exec();
}You can also use a stylesheet.
-
@mrjj when i use one code :-
ui->comboBox->model()->setData(ui->comboBox->model()->index(0, 0), QSize(100, 100), Qt::SizeHintRole);
this one just increase the size icon index size not the down list width.
Also I dont want to show the icon inside the drop list. -
@mrjj said in QT I want to increase the size of comboBox Down list not the drop- Down icon ?:
Just make all items bigger and dropdown also be bigger.
Sorry i am not getting this thing. item bigger and dropdown bigger. But I want only item width bigger
-
@amarism
ok.
you need to subclass for that i think.
https://forum.qt.io/topic/30405/how-to-change-qcombobox-popup-widthAlternatively, you canuse toolbutton and QMenu.
-
@amarism
In what way did it not work for you ?
Seems to work as expected.
class WideComboBox : public QComboBox { Q_OBJECT public: explicit WideComboBox(QWidget *parent = nullptr) : QComboBox(parent) {}; ~WideComboBox() {} public: void showPopup() { this->view()->setMinimumWidth(this->view()->sizeHintForColumn(0)); QComboBox::showPopup(); } };
setting it to 400 ;)
-
Additionally to what @mrjj wrote, you should also be able to set the size of the view via a StyleSheet, a viable option if you don't plan to vary the size all to often
ui->comboBox->setStyleSheet("QComboBox QAbstractItemView {min-width: 400px;}"),