Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QComboBox Vertical Scrollbar are hidden or not showing when stylesheet added

QComboBox Vertical Scrollbar are hidden or not showing when stylesheet added

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 6 Posters 2.0k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rumzi
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You are targeting too broad with the stylesheet so the scrollbar also gets affected.
      Stylesheet should be

      QComboBox {
      padding-right:5px;
      text-align:left;
      font-size:20px; 
      font-family: helvetica; 
      color : #1C6EA4; 
      height:30px;
      }
      

      alt text

      1 Reply Last reply
      7
      • R Offline
        R Offline
        Rumzi
        wrote on last edited by
        #3

        @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.

        jsulmJ 1 Reply Last reply
        0
        • R Rumzi

          @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.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @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

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • R Offline
            R Offline
            Rumzi
            wrote on last edited by
            #5

            Could you help me a small code in this regards.

            Pradeep P NP 1 Reply Last reply
            0
            • R Rumzi

              Could you help me a small code in this regards.

              Pradeep P NP Offline
              Pradeep P NP Offline
              Pradeep P N
              wrote on last edited by Pradeep P N
              #6

              @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.

              Pradeep Nimbalkar.
              Upvote the answer(s) that helped you to solve the issue...
              Keep code clean.

              1 Reply Last reply
              4
              • Shrinidhi UpadhyayaS Offline
                Shrinidhi UpadhyayaS Offline
                Shrinidhi Upadhyaya
                wrote on last edited by Shrinidhi Upadhyaya
                #7

                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:-

                0_1559020481225_c6c1d59e-c577-4fc9-9dbb-0fb986bcd8cd-image.png

                • 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:-

                0_1559020871716_541d8b3d-7c8a-448c-8fad-3cd80df0436d-image.png

                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"]

                Shrinidhi Upadhyaya.
                Upvote the answer(s) that helped you to solve the issue.

                1 Reply Last reply
                3
                • R Offline
                  R Offline
                  Rumzi
                  wrote on last edited by
                  #8

                  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.

                  JonBJ 1 Reply Last reply
                  0
                  • R Rumzi

                    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.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @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.

                    1 Reply Last reply
                    2
                    • R Offline
                      R Offline
                      Rumzi
                      wrote on last edited by
                      #10

                      Thanks bro. It was my mistake. It's working. I am loving Qt and grateful to you all for helping me out.

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved