Results 1 to 2 of 2

Thread: Time Delay for show Color in PushButton

  1. #1
    Join Date
    Apr 2017
    Posts
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Windows

    Default Time Delay for show Color in PushButton

    Hi
    I make a Programm using C++ and Netbeans with a lot of pushbutton

    I would like to do something like this
    When i click the button, it should change to the Position i want and Change the border style or maybe Background to red or whatever and after maybe 300ms it should Change back to normal
    The part with changing Position worked for me.

    I used to Google but I didn found any solution. I try something like this but itsnot work

    Qt Code:
    1. void VerschiebeSpiel::buttonClicked(QWidget* _button){
    2. // Clicked button identifire with QSignalMapper
    3. QPushButton* b = dynamic_cast<QPushButton*>(_button); //cast widget to pushbutton
    4. int index = layout->indexOf(_button); // find out the index of button in gridlayout
    5. int row, col,ax,bx;
    6. if(index != -1){
    7. layout->getItemPosition(index,&row,&col,&ax,&bx); // get the koordinate of this item
    8. }
    9.  
    10. // Set border color
    11. //b->setStyleSheet("border:2px solid #ff0000"); or set Background color
    12. b->setStyleSheet("background-color:green");
    13.  
    14. //make delay time here to Show this Color for only a specific amoun of time like Sleep(MS) in Windows.h
    15. // TODO
    16. //QThread:usleep() seem not work, QTimer i think also dont work
    17.  
    18. b->setStyleSheet(""); // set stylesheet back
    19.  
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 
    Any Solution for this?

    Thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Time Delay for show Color in PushButton

    Changing the position of a button when you click it sounds like a very weird GUI, like one of these tricks that says "Click here" and then the button moves away when you try. I bet it will be very annoying to your users.

    To change the color, you should implement a single-shot QTimer in your button click slot that uses the Functor version of QTimer::singleShot(). To make this easier, you could create a Functor that stores the pointer to the button as well as the default color. When the timeout occurs, the Functor's operator() gets executed and in it you reset the button back to the default state.

    Instead of setting the style sheet, you could also simply use QPalette and store that in the Functor; to change the button's background color, you use the QPalette::Button color role.
    Last edited by d_stranz; 28th April 2017 at 18:29.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Remove color when pushButton is selected
    By alenn.masic in forum Qt Programming
    Replies: 3
    Last Post: 28th November 2012, 21:39
  2. Replies: 5
    Last Post: 15th January 2011, 16:50
  3. Right-Click menu on a pushButton doesn't show up
    By qtpyqt in forum Qt Programming
    Replies: 6
    Last Post: 9th September 2010, 17:58
  4. Replies: 4
    Last Post: 16th February 2009, 07:10
  5. setToolTip time delay
    By h123 in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2008, 09:20

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.