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. QToolbar stylesheet
Forum Update on Monday, May 27th 2025

QToolbar stylesheet

Scheduled Pinned Locked Moved Solved General and Desktop
qtoolbarstyesheet
7 Posts 3 Posters 5.6k 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.
  • Gianluca86G Offline
    Gianluca86G Offline
    Gianluca86
    wrote on last edited by Gianluca86
    #1

    Hello everyone, when a toolbar has too many buttons or resizing the window, you see a button to display the missing buttons. (See image below)
    Screenshot
    I wanted to know if it is possible to increase the width. Looking at the documentation I found nothing, maybe I have not tried the exact name.
    Thank you

    Ni.SumiN 1 Reply Last reply
    0
    • Gianluca86G Gianluca86

      Hello everyone, when a toolbar has too many buttons or resizing the window, you see a button to display the missing buttons. (See image below)
      Screenshot
      I wanted to know if it is possible to increase the width. Looking at the documentation I found nothing, maybe I have not tried the exact name.
      Thank you

      Ni.SumiN Offline
      Ni.SumiN Offline
      Ni.Sumi
      wrote on last edited by Ni.Sumi
      #2

      @Gianluca86 said:

      I wanted to know if it is possible to increase the width

      This you can do using set Geometry, toolbar->setGeometry(x,y,width,height)

      Are you looking some thing like resize the toolbar basing on the mainWindow size? or fixed width of toolbar?

      1 Reply Last reply
      0
      • Gianluca86G Offline
        Gianluca86G Offline
        Gianluca86
        wrote on last edited by
        #3

        No, maybe I explained badly. I will not enlarge the toolbar, but the size of the ">>" button that is circled in red in the image.

        raven-worxR 1 Reply Last reply
        0
        • Gianluca86G Gianluca86

          No, maybe I explained badly. I will not enlarge the toolbar, but the size of the ">>" button that is circled in red in the image.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Gianluca86
          example QSS selector:

          QToolBar > QToolBarExtension#qt_toolbar_ext_button {
              ...
          }
          

          now you can play around with the min-width, margin, etc properties

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1
          • Gianluca86G Offline
            Gianluca86G Offline
            Gianluca86
            wrote on last edited by
            #5

            I tried:

            MainToolBar.setStyleSheet("QToolBar > QToolBarExtension#qt_toolbar_ext_button { background-color: red; min-width: 28px;}");
            

            It seems to work, but cuts the button.
            Screenshot

            raven-worxR 1 Reply Last reply
            0
            • Gianluca86G Gianluca86

              I tried:

              MainToolBar.setStyleSheet("QToolBar > QToolBarExtension#qt_toolbar_ext_button { background-color: red; min-width: 28px;}");
              

              It seems to work, but cuts the button.
              Screenshot

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @Gianluca86
              ah sorry my fault.
              This can't be achieved with QSS only.
              You would need to subclass QProxyStyle and reimplement pixelMetric().
              In there return the desired value for QStyle::PM_ToolBarExtensionExtent

              But i am afraid you can't use QProxyStyle in combination with stylesheets (anywhere in the parent hierarchy), since they rid themselves out mutually.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • Gianluca86G Offline
                Gianluca86G Offline
                Gianluca86
                wrote on last edited by
                #7

                Ok, I tried this:

                // MyStyle.h
                #include <QStyle>
                
                class MyStyle : public QStyle
                {
                public:
                    MyStyle();
                    virtual int pixelMetric(PixelMetric pm, const QStyleOption* option, const QWidget* widget) const ;
                };
                
                // MYStyle.cpp
                #include "MyStyle.h"
                
                MyStyle::MyStyle()
                {
                
                }
                
                int MyStyle::pixelMetric(PixelMetric pm, const QStyleOption* option, const QWidget* widget) const
                {
                  if (pm == QStyle::PM_ToolBarExtensionExtent)
                    return 50; 
                  return QStyle::pixelMetric(pm, option, widget);
                }
                

                Is it correct?

                The line

                return QStyle::pixelMetric(pm, option, widget);
                

                give me this error:
                error: undefined reference to `QStyle::pixelMetric(QStyle::PixelMetric, QStyleOption const*, QWidget const*) const'

                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