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.
  • G Offline
    G Offline
    Gianluca86
    wrote on 20 Jul 2016, 12:37 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

    N 1 Reply Last reply 20 Jul 2016, 12:42
    0
    • G Gianluca86
      20 Jul 2016, 12:37

      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

      N Offline
      N Offline
      Ni.Sumi
      wrote on 20 Jul 2016, 12:42 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
      • G Offline
        G Offline
        Gianluca86
        wrote on 20 Jul 2016, 12:47 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.

        R 1 Reply Last reply 20 Jul 2016, 12:55
        0
        • G Gianluca86
          20 Jul 2016, 12:47

          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.

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 20 Jul 2016, 12:55 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
          • G Offline
            G Offline
            Gianluca86
            wrote on 20 Jul 2016, 13:27 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

            R 1 Reply Last reply 20 Jul 2016, 13:49
            0
            • G Gianluca86
              20 Jul 2016, 13:27

              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

              R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 20 Jul 2016, 13:49 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
              • G Offline
                G Offline
                Gianluca86
                wrote on 20 Jul 2016, 14:20 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

                4/7

                20 Jul 2016, 12:55

                • Login

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