Results 1 to 15 of 15

Thread: QProgressBar takes big steps

  1. #1
    Join Date
    Mar 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QProgressBar takes big steps

    Hi,

    I have a progress bar that keeps pace with the time of an mp3 that is playing. The widget is just over 320 pixels wide and the range is set as (0, total), where "total" is the duration of the mp3 in seconds.

    I can catch every second that has passed and set the value of the progress bar accordingly.

    I would expect the bar to move 1 pixel per step (unless "total" is less than 320 seconds) but it moves 8 pixels at a time and simply waits until the elapsed time justifies such a big step. So even when the mp3 lasts 12 minutes the progress bar takes about 40 steps, each 8 pixels wide.

    I looked for configuration options, but can't find anything relevant.

    Any ideas on this?

    Thanks,

    JS

  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 takes big steps

    Maybe you are not allowing the event loop to process the events?
    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. #3
    Join Date
    Mar 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProgressBar takes big steps

    I can output the elapsed time through prinf several times per second. Doesn't that mean the event loop is quick enough?


    Added after 5 minutes:


    Perhaps a few details can be of use:

    I have subclassed the progress bar, but only to handle mouse events.
    next:

    ds_progress = new qm_clickprogressbar();
    ds_progress->setFixedSize(324,8);
    ds_progress->setMouseTracking(false);
    ds_progress->setProperty("centerIndicator", QVariant(false));
    ds_progress->setProperty("percentageVisible", QVariant(false));
    ds_progress->setTextVisible(false);
    ds_progress->setMinimum(0);

    When I have the total time:

    ds_progress->reset();
    ds_progress->setRange(0,songTotalTime);

    And when I get the current time :

    ds_progress->setValue(curtime);
    Last edited by Jayes; 10th December 2010 at 16:58.

  4. #4
    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 takes big steps

    What is this qm_clickprogressbar class?
    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.


  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProgressBar takes big steps

    Does the percentage increase correctly?
    It very well may be (but I don't know for sure) that the visual presentation for each step has a minimum of X pixels, since the purpose of the progress bar is to let the user know things are still running in the background, so usually a 1:1 visual representation of the current point of the range is not important.
    You can test it by having a progress bar in a test application, where you connect lets say a slider to it.
    There you can see exactly the "leaps" it will take not dependent of events.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #6
    Join Date
    Mar 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProgressBar takes big steps

    Quote Originally Posted by wysota View Post
    What is this qm_clickprogressbar class?
    A subclassed QProgressBar:

    lass qm_clickprogressbar : public QProgressBar
    {
    Q_OBJECT

    public:
    qm_clickprogressbar(QWidget *parent = 0);
    virtual ~qm_clickprogressbar();

    protected:
    void mouseReleaseEvent ( QMouseEvent *e );
    void mousePressEvent ( QMouseEvent *e );

    signals:
    void clicked();
    void clicked(QMouseEvent *e);
    void pressed();
    void pressed(QMouseEvent *e);
    void scrolled(int);
    };


    Added after 14 minutes:


    Quote Originally Posted by high_flyer View Post
    Does the percentage increase correctly?
    I have done this:

    int timenow = function_to_get the_time( );
    ds_progress->setValue(timenow);
    printf ("Current Time: %i\n", timenow);
    printf ("Progress Bar: %i\n", ds_progress->value());

    The result is this:

    Current Time: 1
    Progress Bar: 1
    Current Time: 2
    Progress Bar: 2
    Current Time: 3
    Progress Bar: 3
    Current Time: 4
    Progress Bar: 4
    Current Time: 5
    Progress Bar: 5
    Current Time: 6
    Progress Bar: 6

    Conclusion: The progress bar is set correctly, but it SHOWS only increments of 8 pixels.
    Last edited by Jayes; 10th December 2010 at 18:48.

  7. #7
    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 takes big steps

    What happens if you set the total progress to twice you have now? Will the bar update in steps of 4 pixels?
    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.


  8. #8
    Join Date
    Mar 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProgressBar takes big steps

    Quote Originally Posted by wysota View Post
    What happens if you set the total progress to twice you have now? Will the bar update in steps of 4 pixels?
    No, still 8 pixels. I just takes twice as long before the step is taken.

    By the way ... I think is 8 pixels, but it could be 10. Maybe I can check with screen-dumps.


    Added after 21 minutes:


    Quote Originally Posted by Jayes View Post
    I think is 8 pixels, but it could be 10.
    I did. And I found both 9 and 10 pixel steps, possibly alternating. The total playing time of the song has no effect though.
    Last edited by Jayes; 10th December 2010 at 19:35.

  9. #9
    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 takes big steps

    Ok, second experiment. What if you make the progress bar twice as wide?
    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.


  10. #10
    Join Date
    Mar 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProgressBar takes big steps

    Quote Originally Posted by wysota View Post
    Ok, second experiment. What if you make the progress bar twice as wide?
    I can't. But I made it half as wide: Makes no difference (still 10 px steps).

    I tried yet another experiment: I sent the code to a friend who runs Slackware (I run Debian testing). He compiled it and it works fine: 1 pixel per second. ... QT bug?
    Last edited by Jayes; 10th December 2010 at 20:56.

  11. #11
    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 takes big steps

    Quote Originally Posted by Jayes View Post
    QT bug?
    You'd have to ask Apple - Quick Time is their product

    Run you application with arguments "-style Plastique" and see if it changes anything.
    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.


  12. #12
    Join Date
    Mar 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProgressBar takes big steps

    Quote Originally Posted by wysota View Post
    Run you application with arguments "-style Plastique" and see if it changes anything.
    Whoooo... bingo! That makes all the difference.
    So it is a style bug. Perhaps related to the fact that I run my QT apps on Gnome. Out of my ballpark anyway.

    Thanks for your hint!

    JS

  13. #13
    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 takes big steps

    Quote Originally Posted by Jayes View Post
    So it is a style bug.
    It's not a bug, it's a feature.
    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.


  14. #14
    Join Date
    Mar 2010
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProgressBar takes big steps

    Quote Originally Posted by wysota View Post
    It's not a bug, it's a feature.
    I'll be damned. You are right.
    It is my Gtk theme and it behaves in the same way on Gtk apps.

    Thanks again, and sorry to have bothered you with this.

    JS

  15. #15
    Join Date
    Mar 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProgressBar takes big steps

    Hi there!
    I have the exact same use-case as mentioned here. Using plastique style is not a real solution I think since it messes up the system style (if you don't have everything customized).
    I solved this by calling the progressbar's repaint() method every time it get's a new value.

Similar Threads

  1. Questions after the first steps with Qt
    By MartinM in forum Newbie
    Replies: 2
    Last Post: 26th April 2010, 09:10
  2. Steps for cross compiling
    By Yayati.Ekbote in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 15th March 2010, 16:32
  3. axis ans steps
    By ram1nx in forum Qwt
    Replies: 1
    Last Post: 2nd February 2010, 10:17
  4. steps to connect to SQLite from Q
    By Qt Coder in forum Qt Programming
    Replies: 3
    Last Post: 8th July 2009, 13:12
  5. Custom Widget - First Steps
    By sekatsim in forum Qt Programming
    Replies: 8
    Last Post: 26th June 2008, 18:19

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.