Results 1 to 15 of 15

Thread: QProgressBar takes big steps

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 15: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 17: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.


Similar Threads

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