Results 1 to 12 of 12

Thread: How to set spinner image for qstackwidget ???

  1. #1
    Join Date
    Nov 2011
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Post How to set spinner image for qstackwidget ???

    Hi All,
    I am trying to add a spinner to QStackwidget, i am having 5 frame pages in the stackwidget with 5 buttons below in a seperate frame and when i press the 1st button it should load the spinner image in the frame page and similarly for all others.. In my application,when i give these below codes i am not able to get it.

    QAnimationLabel* spinner = new QAnimationLabel(":images/spinner-24x24.gif", this);
    spinner->start();

    QVBoxLayout* layout = new QVBoxLayout;
    layout->addWidget(spinner, 0, Qt::AlignCenter);
    QFrame* frame = new QFrame;
    frame->setLayout(layout);
    setCentralWidget(frame);

    It's not accepting the SetCentralWidget(frame); and i could not find any solution for this.
    Answers will be highly appreciated!!!

    Thanks in Advance and Regards,
    Naufal.A

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to set spinner image for qstackwidget ???

    You start talking about a QStackedWidget and five buttons, show a code snippet that does not include any reference to a QStackedWidget or five buttons, and then complain that "It's not accepting the SetCentralWidget(frame)" (a QMainWindow function). We know that you are "not able to get it" (whatever it is). There's no error message for us to work with. What are you expecting us to do with this?

    I have no idea what a QAnimationLabel is.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  3. #3
    Join Date
    Nov 2011
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: How to set spinner image for qstackwidget ???

    Hi Chris,
    Actually sorry for that code!!! i need an alternate solution and i had tried using that code only!!!!
    I will explain you clearly again. I am having a stackwidget and above it i kept 5 frames.. below all that i kept 5 buttons for all those pages.. if i press a button it goes to each and every page., i want to add a loader image into it!!! I tried the above codes but i could not find any solution.,

    Can you get my point!!!

    Thanks in Advance and Regards,
    Naufal.A

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set spinner image for qstackwidget ???

    really!!!??? ok!!!!
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to set spinner image for qstackwidget ???

    Quote Originally Posted by naufalahad View Post
    I tried the above codes but i could not find any solution.
    Your code above doesn't even try to address a stack of widgets or a set of buttons. It looks like you didn't even try to find a solution.

    Here is an example with all the elements you describe. I suggest you read the excellent documentation for each class, work out what its purpose is, and come back with specific questions if you cannot work something out.
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class MainWindow: public QMainWindow {
    4. Q_OBJECT
    5. public:
    6. MainWindow(QWidget *p = 0): QMainWindow(p) {
    7. QWidget *central = new QWidget(this);
    8. setCentralWidget(central);
    9.  
    10. QVBoxLayout *layout = new QVBoxLayout;
    11. central->setLayout(layout);
    12.  
    13. QStackedWidget *stack = new QStackedWidget(central);
    14. layout->addWidget(stack);
    15.  
    16. QHBoxLayout *hbox = new QHBoxLayout; // for the buttons
    17. layout->addLayout(hbox);
    18.  
    19. // Construct the stack and buttons
    20. QSignalMapper *mapper = new QSignalMapper(central);
    21. for (int i = 0; i < 5; ++i) {
    22. // Put something on the page
    23. QLabel *label = new QLabel(stack);
    24. label->setPixmap(QPixmap(QString(":/image%1.png").arg(i)));
    25. stack->addWidget(label);
    26.  
    27. // Add a button to select the page
    28. QPushButton *button = new QPushButton(QString("Page %1").arg(i), central);
    29. hbox->addWidget(button);
    30. mapper->setMapping(button, i);
    31. connect(button, SIGNAL(clicked()), mapper, SLOT(map()));
    32. }
    33. connect(mapper, SIGNAL(mapped(int)), stack, SLOT(setCurrentIndex(int)));
    34.  
    35. }
    36. };
    37.  
    38. int main(int argc, char *argv[])
    39. {
    40. QApplication app(argc, argv);
    41. MainWindow m;
    42. m.show();
    43. return app.exec();
    44. }
    45. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    and the resource file:
    Qt Code:
    1. <RCC>
    2. <qresource prefix="/">
    3. <file>image0.png</file>
    4. <file>image1.png</file>
    5. <file>image2.png</file>
    6. <file>image4.png</file>
    7. <file>image3.png</file>
    8. </qresource>
    9. </RCC>
    To copy to clipboard, switch view to plain text mode 
    You need to provide the five image files for the example to work.
    image2.pngimage1.pngimage0.pngimage3.pngimage4.png

  6. The following user says thank you to ChrisW67 for this useful post:

    naufalahad (21st December 2011)

  7. #6
    Join Date
    Nov 2011
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: How to set spinner image for qstackwidget ???

    Hi Chris,
    Thanks for your reply but my idea was to bring a loading page(.gif image) when i press a button at the loading time of every button is pressed to load a page. I will try your code and work it out. Had got some idea from your code.

    Thanks again and Regards,
    Naufal

  8. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to set spinner image for qstackwidget ???

    What are you "loading"? The QStackedWidget pages already exist, and you are just switching from one to another.

  9. #8
    Join Date
    Nov 2011
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: How to set spinner image for qstackwidget ???

    Hi Chris,
    I want to load the loader image (ie, loader.gif image),while the page is loading when the button is pressed....... i need to show this image(loader) before the next page gets loaded!!!
    So only i had given that Qanimation label in the previous code!!! I want to set that in the button part such that when i clicked it should start running the gif image on the screen.. i had ported the API's of the loading page but could not able to port them into the button.. I tried those code which i mentioned above in the button part but could not find that is running or not... Did u get my point!!!! In-case no tell me chris i will explain you with my codes too.

    Thanks in advance and Regards,
    Naufal.A

  10. #9
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set spinner image for qstackwidget ???

    why are your pages loading so slow that you need a 'loader image'? How do you know when the page is finished loading?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  11. #10
    Join Date
    Nov 2011
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: How to set spinner image for qstackwidget ???

    Hi Amleto,
    I will stop them when the page gets loaded from the server, i am getting the parse value., at that time i need to put this loading image into it.

    Could you find me any answers for this!!! will be very much helpful

    Thanks in advance and Regards,
    Naufal.A

  12. #11
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set spinner image for qstackwidget ???

    the loading image works fine from your code here
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  13. #12
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to set spinner image for qstackwidget ???

    I think this is where we are at... Your actual query has:
    • Nothing to do with QStackedWidget
    • Nothing to do with QMainWindow and setCentralWidget()
    • Nothing to do with five buttons selecting pages in a stacked widget
    • Nothing to do with the loading of a stacked page

    Excellent way to ask a smart question.

    It is still vague, but I think:

    You simply want to display a popup window (or unhide a widget) with an animated gif in it (instead of using something like QProgressBar). The popup should stay until dismissed/hidden at the end of some unspecified loading period.

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class LoadingWidget: public QLabel {
    4. Q_OBJECT
    5. public:
    6. LoadingWidget(QWidget *p = 0): QLabel(p) {
    7. movie = new QMovie(":/loading.gif", QByteArray(), this);
    8. setMovie(movie);
    9. }
    10. protected:
    11. void showEvent ( QShowEvent * event ) {
    12. movie->start();
    13. QLabel::showEvent(event);
    14. }
    15. void hideEvent ( QHideEvent * event ) {
    16. movie->stop();
    17. QLabel::hideEvent(event);
    18. }
    19. private:
    20. QMovie *movie;
    21. };
    22.  
    23.  
    24. int main(int argc, char *argv[])
    25. {
    26. QApplication app(argc, argv);
    27.  
    28. LoadingWidget l;
    29. l.resize(64, 64);
    30. l.show();
    31.  
    32. // Simulate a 5 second load time then close (or hide)
    33. QTimer::singleShot(5000, &l, SLOT(close()));
    34.  
    35. return app.exec();
    36. }
    37. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    You can provide your own loading.gif.

Similar Threads

  1. QTreeWidget and QStackWidget
    By Paulo Fernando Pimenta in forum Newbie
    Replies: 3
    Last Post: 1st March 2011, 18:27
  2. Qmovie spinner.gif image Problem
    By pavanbarot in forum Qt Programming
    Replies: 0
    Last Post: 31st October 2010, 12:07
  3. ShowFullScreen on QStackWidget don't work
    By Ratheendrans in forum Qt Programming
    Replies: 2
    Last Post: 10th May 2010, 18:34
  4. QStackWidget layoutspacing
    By killerwookie99 in forum Qt Programming
    Replies: 2
    Last Post: 14th August 2008, 21:38
  5. Reuse a Qwidget with a QStackWidget
    By ucomesdag in forum Qt Programming
    Replies: 4
    Last Post: 25th April 2007, 02:47

Tags for this Thread

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.