Solved QComboBox how to change tab stop width?
-
Hello,
in a QComboBox each item string consists of two parts. And the second string part should be aligned to the second string parts of all following combobox rows.
I tried to achieve this using a tabulator (\t) in the item strings. But the tabulator width is too large and I couldn't find a way to change it:
#include <QApplication> #include <QWidget> #include <QComboBox> int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget w; QComboBox combo1(&w); combo1.setStyleSheet("QComboBox { combobox-popup: 0; }"); combo1.setFont(QFont("Roboto",10)); combo1.setGeometry(20,20,300,25); QString string1("A\t:Something"); combo1.addItem(string1); QString string2("DNX\t:Something"); combo1.addItem(string2); QString string3("B\t:Something"); combo1.addItem(string3); QString string4("KLQ\t:Something"); combo1.addItem(string4); QString string5("GT\t:Something"); combo1.addItem(string5); QString string6("F\t:Something"); combo1.addItem(string6); w.show(); w.resize(340, 200); return a.exec(); }
This is how it looks like. The selected item (inside the gray field) is ok, but the tabulator width of all items in the combobox dropdown menu is too large:
Is there any way to change the tabulator width in the combobox dropdown menu? If not how to achieve the wished alignment? How is that done?
Regards,
mireiner -
@mireiner said in QComboBox how to change tab stop width?:
Is there any way to change the tabulator width in the combobox dropdown menu?
It's not
If not how to achieve the wished alignment?
Write your own QStyledItemDelegate and to the alignment by your own.
-
Hello Christian,
I'll will look into the QStyledItemDelegate and see how it works.
Thank you for the help!