QComboBox Vertical Scrollbar are hidden or not showing when stylesheet added
-
wrote on 26 May 2019, 05:47 last edited by
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
-
-
@mrjj , are you referring to QML? I am using Qt 4.8. How to call a qml file in my cpp file? I didn't get it. Sorry it's my lack of understanding. Need a little bit details.
@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
-
wrote on 28 May 2019, 05:04 last edited by
Could you help me a small code in this regards.
-
wrote on 28 May 2019, 05:06 last edited by Pradeep P N
@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.
-
wrote on 28 May 2019, 05:26 last edited by Shrinidhi Upadhyaya
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"] -
wrote on 28 May 2019, 10:02 last edited by
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. -
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.wrote on 28 May 2019, 10:08 last edited by@Rumzi
Both @mrjj & @Shrinidhi-Upadhyaya show screenshots which do show a vertical scrollbar, so what do you mean? The scrollbar will only be shown if there are items to scroll. -
wrote on 29 May 2019, 03:26 last edited by
Thanks bro. It was my mistake. It's working. I am loving Qt and grateful to you all for helping me out.
1/10