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. Stylesheet for the arrows on the QListView of a QCombobox

Stylesheet for the arrows on the QListView of a QCombobox

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 779 Views
  • 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.
  • C Offline
    C Offline
    CDieguez
    wrote on last edited by CDieguez
    #1

    c9eb2c34-4890-4029-b1c0-589425bca94b-image.png

    I'm trying to create a stylesheet for a QCombobox and this is the QListView that pops when I select the QCombobox. How can I style those arrows on the top and bottom of the list?
    I found references to the arrows on QScrollBar, but i can't find references to these two.

    jsulmJ 1 Reply Last reply
    0
    • C CDieguez

      c9eb2c34-4890-4029-b1c0-589425bca94b-image.png

      I'm trying to create a stylesheet for a QCombobox and this is the QListView that pops when I select the QCombobox. How can I style those arrows on the top and bottom of the list?
      I found references to the arrows on QScrollBar, but i can't find references to these two.

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

      @CDieguez https://doc.qt.io/qt-6/stylesheet-examples.html
      See "Customizing QComboBox"

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

      C 1 Reply Last reply
      1
      • jsulmJ jsulm

        @CDieguez https://doc.qt.io/qt-6/stylesheet-examples.html
        See "Customizing QComboBox"

        C Offline
        C Offline
        CDieguez
        wrote on last edited by CDieguez
        #3

        @jsulm Sorry, I'm just not seeing it.
        I'm already styling "QComboBox::down-arrow" and "CComboBox::drop-down" to make the combobox look like this.
        a6f5d50f-8fc0-4328-a5de-083c37e0f46f-image.png
        For smaller lists, those arrows don't appear and it looks fine.

        I styled "QComboBox QAbstractItemView { " to set the padding, background color, selection color, item selection border for the itens on the ListView.

        The only things in the example I'm not using are the "on" and "editable" states. I'm not planning on allowing the user to edit the combobox and I don't want it to look different if it's on or not.

        To see if I could change the color of those arrow buttons to red, I literally tried styling something similar to the example below for every sub-control on the List of Sub-Controls in this link https://doc.qt.io/qt-6/stylesheet-reference.html#sub-line-sub, but nothing changed those two buttons.

        "CComboBox::down-arrow {"
             "background-color: red;"
        "}"
        "CComboBox::float-button {"
             "background-color: red;"
        "}"
        "CComboBox::indicator {"
             "background-color: red;"
        "}"
        ...
        

        I'm just looking for the name of these sub-controls or if they should be addressed as another class instead of a sub-control. I really would appreciate an example like the ones above that could turn those two arrows red or set an image or change them in any way.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          CDieguez
          wrote last edited by
          #4

          2 years later and this is still a mistery to me, what sub-control is this two arrows in the combobox popup? I hope I can use AI today to search for it...

          1 Reply Last reply
          0
          • C Offline
            C Offline
            CDieguez
            wrote last edited by
            #5

            Using AI to search inside Qt 5.6.3 base code, it suggested this code to manipulate these arrows. I'd prefer using qss, but this approach actually worked.

            // Event filter to customize the painting of QComboBoxPrivateScroller widgets
            class ScrollerPaintFilter : public QObject
            {
            public:
              ScrollerPaintFilter(int button_height, QObject* parent = nullptr)
                : QObject(parent), button_height_(button_height) {}
            
            protected:
              bool eventFilter(QObject* obj, QEvent* event) override
              {
                if (event->type() == QEvent::Paint)
                {
                  QWidget* widget = qobject_cast<QWidget*>(obj);
                  if (widget)
                  {
                    QPaintEvent* paintEvent = static_cast<QPaintEvent*>(event);
                    QPainter p(widget);
                    
                    // Fill background
                    p.fillRect(widget->rect(), QColor(gray);
                    
                    // Draw border
                    p.setPen(QPen(Qt::black, 1));
                    p.drawRect(widget->rect().adjusted(0, 0, -1, -1));
                    
                    // Determine if this is up or down scroller by checking y position
                    bool is_down = widget->y() > widget->parentWidget()->height() / 2;
                    
                    // Draw arrow icon
                    QPixmap arrow(is_down ? "down.png" : "up.png");
                    int icon_x = widget->rect().center().x() - arrow.width() / 2;
                    int icon_y = widget->rect().center().y() - arrow.height() / 2;
                    p.drawPixmap(icon_x, icon_y, arrow);
                    
                    return true; // Event handled, don't call original paintEvent
                  }
                }
                return QObject::eventFilter(obj, event);
              }
            
            private:
              int button_height_;
            };
            
            void ComboBox::showPopup()
            {
            ...
              // Get the popup widget
              QWidget* popup = view()->parentWidget();
            
              // Customize Qt's built-in scroll indicators (top and bottom arrows)
              // These are QComboBoxPrivateScroller widgets that Qt creates automatically
              QList<QWidget*> children = popup->findChildren<QWidget*>();
              ScrollerPaintFilter* filter = new ScrollerPaintFilter(popup);
              
              for (QWidget* child : children)
              {
                if (child->inherits("QComboBoxPrivateScroller"))
                {
                  // Set fixed height to match button height
                  child->setFixedHeight(button_height);
                  
                  // Install event filter to custom paint the scroller
                  child->installEventFilter(filter);
                }
              }
            ...
            }
            
            1 Reply Last reply
            0
            • C Offline
              C Offline
              CDieguez
              wrote last edited by
              #6

              Captura de tela 2026-02-04 190030.png

              1 Reply Last reply
              0

              • Login

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