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. No percentage label on QProgressBar when switching to vertical
Forum Updated to NodeBB v4.3 + New Features

No percentage label on QProgressBar when switching to vertical

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 1.0k Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    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
    0
    • H Offline
      H Offline
      hkottmann
      wrote on last edited by
      #3

      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?

      JonBJ 1 Reply Last reply
      0
      • H hkottmann

        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?

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #4

        @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
        0
        • H Offline
          H Offline
          hkottmann
          wrote on last edited by
          #5

          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
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #6

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

            alt text

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #7

              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

              mrjjM 1 Reply Last reply
              0
              • SGaistS SGaist

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

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #8

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

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

                  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
                  1
                  • H Offline
                    H Offline
                    hkottmann
                    wrote on last edited by
                    #10

                    Hi mrjj

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

                    mrjjM 1 Reply Last reply
                    0
                    • H hkottmann

                      Hi mrjj

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

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

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

                      • Login

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