QComboBox Vertical Scrollbar are hidden or not showing when stylesheet added
-
When I add stylesheet the QComboBox don't show scrollbar. Following are my style
StyleSheet:padding-right:5px;text-align:left;font-size:20px; font-family: helvetica; color : #1C6EA4; height:30px;
Following is my code:
QComboBox *qb=new QComboBox();
qb->setStyleSheet("padding-right:5px;text-align:left;font-size:20px; font-family: helvetica; color : #1C6EA4; height:30px;");Please help
-
Hi
You are targeting too broad with the stylesheet so the scrollbar also gets affected.
Stylesheet should beQComboBox { padding-right:5px; text-align:left; font-size:20px; font-family: helvetica; color : #1C6EA4; height:30px; }
-
@Rumzi said in QComboBox Vertical Scrollbar are hidden or not showing when stylesheet added:
are you referring to QML?
No, he means stylesheets with Qt widgets (QComboBox is a widget and does not have anything to do with QML): https://doc.qt.io/qt-5/stylesheet-reference.html
-
@Rumzi
Use the code provided by @mrjj in the Stylesheet. it will work.
in your case code should be something like below for Qt ComboBox (QComboBox)qb->setStyleSheet("QComboBox { padding-right:5px; text-align:left; font-size:20px; font-family: helvetica; color : #1C6EA4; height:30px; }");
or
qb->setStyleSheet("QComboBox { " "padding-right:5px; " "text-align:left; " "font-size:20px; " "font-family: helvetica; " "color : #1C6EA4; height:30px; " "}");
And for QML ComboBox and styling please refer ComboBox and ComboBoxStyle
QML has rich GUI, if you want the QML Code just let me know.Good luck.
-
Hi @Rumzi , here is the sample code:-
QStringList list; //####Appending the list for (int i = 0; i < 20; i++) { list.append("Count :: "+QString::number(i)); } QComboBox *qb=new QComboBox(this); //####Setting the geometry(x,y,width,height) qb->setGeometry(10,10,80,30); //####Setting the stylesheet you need qb->setStyleSheet("QComboBox { padding-right:5px;text-align:left;font-size:20px;font-family: helvetica; color : #1C6EA4; height:30px;}"); //####Add items to the combo box qb->addItems(list);
Output of the sample code:-
- As you had asked about qml, with qml you can get rich UI.
The sample code for ComboBox in qml:-
ComboBox { id: control width: 200 height: 50 model: 20 //####Custom Text delegate: ItemDelegate { width: control.width contentItem: Text { text: modelData color: "#21be2b" elide: Text.ElideRight verticalAlignment: Text.AlignVCenter font.pixelSize: 40 } highlighted: control.highlightedIndex === index } }
Sample output:-
For more information about:-
StyleSheet["https://doc.qt.io/qt-5/stylesheet-reference.html"]
QML["https://doc.qt.io/qt-5/qtqml-index.html"]
Combo Box(QML)["https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html"]
Customizing Combo Box(QML)["https://doc.qt.io/qt-5/qtquickcontrols2-customize.html#customizing-combobox"] -
Thanks bro.
@Shrinidhi-Upadhyaya , but it's not showing the Vertical scroll bar. The main problem is that using stylesheet making desire look but lack of scroll bar. As I am using Qt 4.8 , if you suggest then it will be very helpful for me. TIA.