Results 1 to 10 of 10

Thread: How can I have a Progressbar with movement

  1. #1
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How can I have a Progressbar with movement

    Hi,

    I want to have a progressbar with some movement on it so the user can be able to know if the application is responding and wroking or not.

    Something like this being a pbar: http://www.telex.com/binary/mapLoadB...2tpbbkj2Zu.gif

    Any idea about if Qt allows you to do it?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How can I have a Progressbar with movement

    Some platforms have an animation for progressbars even when there is no change to the actual value.

    If you want a progressbar that shows progress for an unknown "total", set both minimum and maximum to 0 and just increment the value on each step.

    Cheers,
    _

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

    d_stranz (7th January 2015)

  4. #3
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How can I have a Progressbar with movement

    Hi,

    If I put

    ui->pBar->setMinimum(0);
    ui->pBar->setMaximum(0);
    and then when I want I put: ui->pBar->setValue(value); incrementing the value everytime I call this line

    then the pbar is static and does nothing, not movement and not increment.

  5. #4
    Join Date
    Oct 2013
    Posts
    41
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How can I have a Progressbar with movement

    my first thought would be to make sure your event loop is running while you are incrementing the value

  6. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How can I have a Progressbar with movement

    Yes, this definitely works.

    Qt Code:
    1. #include <QtWidgets>
    2.  
    3. int main(int argc, char ** argv)
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. bar.setMinimum(0);
    8. bar.setMaximum(0);
    9. bar.resize(300, bar.sizeHint().height());
    10. bar.show();
    11.  
    12. QTimer timer;
    13. QObject::connect(&timer, &QTimer::timeout, [&bar]() { bar.setValue(bar.value() + 1); });
    14. timer.start(500);
    15.  
    16. return app.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. TEMPLATE = app
    2.  
    3. QT += widgets
    4. CONFIG += c++11
    5.  
    6. SOURCES = progressbartest.cpp
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How can I have a Progressbar with movement

    Looks like your gui thread is busy doing stuff and cant update the progressbar. So either move your logic to another thread or call processEvents somewhere periodically.

  8. #7
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How can I have a Progressbar with movement

    Hi,

    anda_skoa thanks for your time. About your answer.. that code gaves me so much problems.

    Obviously I don't have this cpp... dunno for what is that line but I didnt wrote it:
    Qt Code:
    1. SOURCES = progressbartest.cpp
    To copy to clipboard, switch view to plain text mode 

    But apart of that it says that:
    void QTimer::timeout() is protected
    and
    no matching function for call to 'QObject::connect(QTimer*, void (QTimer::*)(),miain(int, char**)::<lambda()>)'

    Im using this version of Qt over unix:

    Qt Creator 2.8.0
    Based on Qt 4.8.5

  9. #8
    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: How can I have a Progressbar with movement

    Quote Originally Posted by roseicollis View Post
    Im using this version of Qt over unix:

    Qt Creator 2.8.0
    Based on Qt 4.8.5
    I suggest you update your forum user profile as it says you are using Qt5. The code anda_skoa provided will not work with Qt4 as it is using a lambda expression. I'm not sure why you'd run it though, if he says it works then you should focus on what is different in your own code.
    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. #9
    Join Date
    Dec 2014
    Posts
    82
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How can I have a Progressbar with movement

    Nish I already have 2 threads, one for GUI and another for the background job... but I must be doing something wront

    wysota, totally agree with u, I have to apologize to anda_skoa.. I thought I was using Qt5 until I wanted to verify it and saw that -.-'' I've tried to use it just like
    mybar.setMinimum(0);
    mybar.setMaximum(0);

    but then the thread stops because I have a gif on it (until I get that pbar with movement) and it stops moving....

  11. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How can I have a Progressbar with movement

    Quote Originally Posted by roseicollis View Post
    Obviously I don't have this cpp... dunno for what is that line but I didnt wrote it:
    Qt Code:
    1. SOURCES = progressbartest.cpp
    To copy to clipboard, switch view to plain text mode 
    That is obviously the C++ code I've posted.

    Quote Originally Posted by roseicollis View Post
    Based on Qt 4.8.5
    Works the same way in Qt4 as far as the progressbar is concerned.

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Advancer : public QObject
    4. {
    5. Q_OBJECT
    6. public:
    7. explicit Advancer(QProgressBar *bar) : QObject(bar), mBar(bar)
    8. {
    9. connect(&mTimer, SIGNAL(timeout()), this, SLOT(advance()));
    10. }
    11.  
    12. void start(int interval)
    13. {
    14. mTimer.start(interval);
    15. }
    16.  
    17. private:
    18. QProgressBar *mBar;
    19. QTimer mTimer;
    20.  
    21. private slots:
    22. void advance()
    23. {
    24. mBar->setValue(mBar->value() + 1);
    25. }
    26. };
    27.  
    28. int main(int argc, char ** argv)
    29. {
    30. QApplication app(argc, argv);
    31.  
    32. bar.setMinimum(0);
    33. bar.setMaximum(0);
    34. bar.resize(300, bar.sizeHint().height());
    35. bar.show();
    36.  
    37. Advancer *advancer = new Advancer(&bar);
    38. advancer->start(500);
    39.  
    40. return app.exec();
    41. }
    42.  
    43. #include "progressbartestqt4.moc"
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. TEMPLATE = app
    2.  
    3. SOURCES = progressbartestqt4.cpp
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Maximum value of ProgressBar
    By jesse_mark in forum Newbie
    Replies: 4
    Last Post: 10th January 2013, 14:27
  2. progressbar from right to left.
    By kumari arpita in forum Newbie
    Replies: 2
    Last Post: 1st August 2012, 07:22
  3. Confused with progressbar
    By hakermania in forum Newbie
    Replies: 2
    Last Post: 23rd January 2011, 10:47
  4. Indefinite ProgressBar
    By csvivek in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2008, 11:02
  5. Progressbar problem
    By thae in forum Qt Programming
    Replies: 4
    Last Post: 4th November 2006, 11:48

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.