Results 1 to 5 of 5

Thread: Possible to set duration of QPushButton Pressed event?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2017
    Posts
    54
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Possible to set duration of QPushButton Pressed event?

    Solved: I used:
    Qt Code:
    1. self.ui.SaveBtn.setText('SAVED')
    2. self.ui.SaveBtn.setStyleSheet('background-color: #99ff99; border: 2px solid #097547; ')
    3. QTimer.singleShot(1500, self.normalbtn)
    To copy to clipboard, switch view to plain text mode 

    The self.normalbtn is a function that returns the button to original text and color

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Possible to set duration of QPushButton Pressed event?

    Solved: I used:
    That is the solution I was about to suggest. Your original code shows a misunderstanding of how QTimer works. You do not start a QTimer and then keep checking it until it goes to zero. Instead, you connect a slot to the QTimer's timeout() signal. The timer will count down by itself, and fire the signal when it reaches zero. In the meantime, your application goes about doing whatever it needs to do and reacts only when the slot gets called.

    (This is like almost every other GUI widget in Qt - you create it, connect your slots to its signals, and then your app runs in the event loop until one of those signals gets emitted and your slot called).

    A QTimer as a member variable in a class can be reused as many times as you want. A single-shot timer works once, so you need to set it up every time you want to use it.
    <=== 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. Replies: 4
    Last Post: 2nd April 2013, 09:38
  2. Replies: 2
    Last Post: 26th October 2011, 15:41
  3. Replies: 2
    Last Post: 12th September 2011, 15:40
  4. Removing pressed effect from a QPushButton
    By Luc4 in forum Qt Programming
    Replies: 3
    Last Post: 14th August 2010, 11:43
  5. Delay Loop until a QPushButton pressed
    By ljshap in forum Newbie
    Replies: 6
    Last Post: 17th January 2009, 16:30

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
  •  
Qt is a trademark of The Qt Company.