Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem with styling undetermined QProgressBar



  • Hallo,
    I have trouble setting the style for a undetermined QProgressBar.
    From the docs I know there should be an option.
    https://doc.qt.io/qt-5/qprogressbar.html#setRange
    https://doc.qt.io/qt-5/stylesheet-reference.html there it is mentioned that there is a thing called :indeterminate

    The main problem is that my QProgressBar::chunk only partly applies to the undetermined progress bar.
    My style looks like this:

          m_pProgressBar->setStyleSheet(QString::fromUtf8(R"(
            QProgressBar {
              border-image: url(:/images/launcher/ProgressBar_BG.png);
              font-family: "Verdana";
              font-size: 13px;
              font-weight: bold;
              color: #bfbfbf;
              text-align: center;
            }
            QProgressBar::chunk {
              border-image: url(:/images/launcher/ProgressBar.png);
              margin-top: 2px;
              margin-left: 2px;
              margin-bottom: 3px;
              margin-right: 3px;
            }
          )"));
    

    The QProgressBar::chunk style works perfectly.
    But the funny thing is, for the undetermined version it takes nearly everything form QProgressBar::chunk but margin-left: 2px; and margin-right: 3px;. So the endless running progress indicator overlaps with my border from the ProgressBar_BG.png.
    I'm using Qt 5.5 and that can't be changed currently.

    I have already tried QProgressBar::chunk:indeterminate and QProgressBar:indeterminate and some other less likely combinations. Also with : and ::. Might be that I missed the single version that works.

    So if you have any advice or suggestion how to fix that I'm happy to give it a try!

    Thanks a lot.
    Cheers
    Tobias



  • I found the solution:
    https://doc.qt.io/qt-5/stylesheet-customizing.html#box-model
    The bug in the current code was that that we tried to use margins instead of borders.

          m_pProgressBar->setStyleSheet(QString::fromUtf8(R"(
            QProgressBar {
              border-image: url(:/images/launcher/ProgressBar_BG.png);
              font-family: "Verdana";
              font-size: 13px;
              font-weight: bold;
              color: #bfbfbf;
              text-align: center;
              border-top: 2px;
              border-left: 2px;
              border-bottom: 3px;
              border-right: 3px;
            }
            QProgressBar::chunk {
              border-image: url(:/images/launcher/ProgressBar.png);
            }
          )"));
    

    Setting the borders correct in the Style and not using margins in the ```Style::chunk```` solved the problem.



  • @Tobias
    The bad news is that https://www.qtcentre.org/threads/33170-Customizing-indeterminate-QProgressBar asked and tried the same as you to style the :indetermiate back in 2010, but got no replies :(

    I would have thought it is supposed to be QProgressBar:indeterminate, no mention of ::chunk, (it applies the the QProgressBar as a whole), but I think you've both tried that.



  • @JonB Thank you, I already tried this and did not work.



  • I found the solution:
    https://doc.qt.io/qt-5/stylesheet-customizing.html#box-model
    The bug in the current code was that that we tried to use margins instead of borders.

          m_pProgressBar->setStyleSheet(QString::fromUtf8(R"(
            QProgressBar {
              border-image: url(:/images/launcher/ProgressBar_BG.png);
              font-family: "Verdana";
              font-size: 13px;
              font-weight: bold;
              color: #bfbfbf;
              text-align: center;
              border-top: 2px;
              border-left: 2px;
              border-bottom: 3px;
              border-right: 3px;
            }
            QProgressBar::chunk {
              border-image: url(:/images/launcher/ProgressBar.png);
            }
          )"));
    

    Setting the borders correct in the Style and not using margins in the ```Style::chunk```` solved the problem.


Log in to reply