Results 1 to 2 of 2

Thread: QProgressBar chunk edges goes out of bounds

  1. #1
    Join Date
    Sep 2009
    Posts
    2
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Unhappy QProgressBar chunk edges goes out of bounds

    Hi all,

    First of all I have to say that I'm totally new to Qt and GUI design (a few days only indeed ). So please forgive my poor style and silly question. I have this issue on Qt 4.5.2 embedded version, however since I do not think it's related to embedded, I'm posting it here.

    My problem is, I need a progress bar with rounded ends (totally circular ends with radius equal to half height of the bar) but I couldn't manage to make it appear the way I want. Setting the radius for progressbar ends is straight forward and the progressbar itself has the shape I want. However, the chunk of the progressbar keeps its rectangular shape and goes out of bounds at both left and right ends. Is there a way to keep those chunk-ends somehow underneath or transparent?

    You could probably suggest giving radius to chunk borders as well. It solves some parts of the issue but brings in some other issues too If I do that, for small values of progress bar fill-ratio (let's say 4%), chunk still has a rectangular shape rather than rounded Probably it cannot complete the circle for such a big radius with such a low size or something like that.

    I have also tried changing chunk width but it didn't work either.

    Hopefully there is a better answer than placing a mask image on the progress bar with transparent center and opaque ends. So, what are your suggestions?

    For your reference, I have also copy-pasted the stylesheet part of Qt Designer and size settings of the containing widget & progressbar itself.

    Thank you very much for your help in advance.

    Qt Code:
    1. QProgressBar { background-color: rgb(161, 161, 161); border: 2px solid grey; border-radius: 25px; color: rgb(255, 255, 255); text-align: right; margin-right: 4ex; }
    2. QProgressBar::chunk { background-color: rgb(255, 255, 255); border-top-left-radius: 23px; border-bottom-left-radius: 23px; width: 1px }
    To copy to clipboard, switch view to plain text mode 

    Progress bar placement code to give an idea about the size.
    Qt Code:
    1. sub_widget_1Class->resize(426, 76);
    2. progressBar->setGeometry(QRect(13, 13, 400, 50));
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProgressBar chunk edges goes out of bounds

    I would suggest to implement your own style (subclassing one of available styles, of course) or subclass the progress bar and correct the drawing in the paint event. The simplest way would be to clip the painter to the rounded shape. But I'd still go for subclassing one of QStyle subclasses. Then it's just a matter of reimplementing QStyle::drawControl() for QStyle::CE_ProgressBarContents and QStyle::CE_ProgressBarGroove.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    lupo (4th September 2009)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.