Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved No percentage label on QProgressBar when switching to vertical

    General and Desktop
    4
    11
    298
    Loading More Posts
    • 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.
    • H
      hkottmann last edited by

      I need to have a QProgressBar that is vertically aligned to show the visually the content of a solution container. When I align the QProgressBar horizontally I have the label visible that shows the percentage, when I align the QProgressBar vertically the label with the percentage is not visible anymore.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        What version of Qt ?
        On what platform ?

        Please provide a minimal compilable example that shows the behaviour.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • H
          hkottmann last edited by

          Hi, thank you for your answer, it's QT 5.14.1 on Windows, is there a way to upload the *.ui-File in this forum?

          JonB 1 Reply Last reply Reply Quote 0
          • JonB
            JonB @hkottmann last edited by

            @hkottmann
            No. Paste into a reply (preferably enclosed in Code tags), or you have to upload somewhere public and give a link.

            1 Reply Last reply Reply Quote 0
            • H
              hkottmann last edited by

              Look like this is still this old unresolved bug:

              https://bugreports.qt.io/browse/QTBUG-31385?focusedCommentId=304710&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel

              The problem is the same in Windows and Linux, here the screenshot of a widget with a horizontal and a vertical QProgressBar with the same settings (except the orientation):

              ![alt text](qprgressbar.png progressbar.png)

              Here the code of the *.ui file:

              <?xml version="1.0" encoding="UTF-8"?>
              <ui version="4.0">
               <class>MainWindow</class>
               <widget class="QMainWindow" name="MainWindow">
                <property name="geometry">
                 <rect>
                  <x>0</x>
                  <y>0</y>
                  <width>373</width>
                  <height>465</height>
                 </rect>
                </property>
                <property name="windowTitle">
                 <string>MainWindow</string>
                </property>
                <widget class="QWidget" name="centralwidget">
                 <layout class="QGridLayout" name="gridLayout_2">
                  <item row="0" column="0">
                   <layout class="QGridLayout" name="gridLayout">
                    <item row="0" column="0">
                     <widget class="QProgressBar" name="progressBar">
                      <property name="value">
                       <number>24</number>
                      </property>
                     </widget>
                    </item>
                    <item row="0" column="1">
                     <widget class="QProgressBar" name="progressBar_2">
                      <property name="value">
                       <number>24</number>
                      </property>
                      <property name="orientation">
                       <enum>Qt::Vertical</enum>
                      </property>
                     </widget>
                    </item>
                   </layout>
                  </item>
                 </layout>
                </widget>
                <widget class="QMenuBar" name="menubar">
                 <property name="geometry">
                  <rect>
                   <x>0</x>
                   <y>0</y>
                   <width>373</width>
                   <height>30</height>
                  </rect>
                 </property>
                </widget>
                <widget class="QStatusBar" name="statusbar"/>
               </widget>
               <resources/>
               <connections/>
              </ui>
              
              
              1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion last edited by mrjj

                Hi
                Seems like the bug is still around
                Win 10. Qt 5.14.1

                alt text

                1 Reply Last reply Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  Since you have them, would either of you please update that report with a minimal compilable example ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  mrjj 1 Reply Last reply Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion @SGaist last edited by

                    @SGaist
                    I added a comment with reference to this thread. ( with how to reproduce )
                    Hope that is fine.

                    1 Reply Last reply Reply Quote 0
                    • mrjj
                      mrjj Lifetime Qt Champion last edited by mrjj

                      Hi
                      A fix could be using a QProxyStyle
                      (fast made, give it more love if used for real)
                      set with
                      ui->progressBar->setStyle( new Progressproxy );

                      class Progressproxy : public QProxyStyle
                      {
                      
                      public:
                          Progressproxy() : QProxyStyle() {}
                      public:
                          virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p,
                                                   const QWidget *w) const override
                          {
                      
                              if (element == CE_ProgressBarLabel) {
                                  const QStyleOptionProgressBar *real  = qstyleoption_cast<const QStyleOptionProgressBar *>(opt);
                                  // check real is not null...
                                  QStyleOptionProgressBar pb = *real;
                                  pb.rect = QRect(0, 0, w->width(), w->height());
                                  proxy()->drawItemText(p, pb.rect, Qt::AlignCenter, pb.palette,
                                                        pb.state & State_Enabled, pb.text, QPalette::Text);
                                  return;
                              }
                      
                              QProxyStyle::drawControl(element, opt, p, w);
                      
                          }
                      };
                      

                      alt text

                      But to have it reserve space in the button of the bar like on horizontal, it seems one has to handle
                      all CE_ProgressBarXXX elements and reduce the rect (clientArea)
                      as the space used for the text seems not included when vertical.
                      (it uses the full widget area)
                      alt text

                      1 Reply Last reply Reply Quote 1
                      • H
                        hkottmann last edited by

                        Hi mrjj

                        Nice hack, this enabled me also to display the percentage value as double value, thank you

                        mrjj 1 Reply Last reply Reply Quote 0
                        • mrjj
                          mrjj Lifetime Qt Champion @hkottmann last edited by

                          @hkottmann
                          Hi
                          Well, that sounds good as i was not sure having the value center would be ok since its normally at the end,
                          and if you can tweak it for something you wanted, its a win.
                          Also, its a small hack and while i didn't test it, it should also respond
                          as expected on other properties (like disabled etc) since im
                          using the normal draw functions.

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post