Results 1 to 8 of 8

Thread: disable press effect for QPushButton

  1. #1
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default disable press effect for QPushButton

    Hi everyone,
    I want to change pushbutton color on click. Suppose if current color is red, on click it ll change to green and after release also it ll be green. There should not any effect between red and green.

    Can anybody please help me ?

    Thanks.

  2. #2
    Join Date
    Sep 2014
    Posts
    1
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo

    Default Re: disable press effect for QPushButton

    Why do you use then a QPushbutton? There are another controls for thi e.g canvas. You can connect it with a onClick method. I think this is easier to make an custom button.

  3. #3
    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: disable press effect for QPushButton

    Quote Originally Posted by bibhukalyana View Post
    I want to change pushbutton color on click. Suppose if current color is red, on click it ll change to green and after release also it ll be green. There should not any effect between red and green.
    Hmm... subclass and reimplement paintEvent. Or use stylesheets if your Qt version supports it. Or implement a custom widget. Whichever suits you best.
    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.


  4. #4
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: disable press effect for QPushButton

    Thanks for reply.

    Quote Originally Posted by fecub View Post
    There are another controls for thi e.g canvas
    I dont know about canvas. Is qt 4.7 supports canvas ? Can you please give some example or link ?
    What are other controls which can be used ?

    Quote Originally Posted by wysota View Post
    Hmm... subclass and reimplement paintEvent. Or use stylesheets if your Qt version supports it. Or implement a custom widget. Whichever suits you best.
    Yes I was trying to reimplement the paintEvent. But I have some queries. How I will know paintEvent is called for focus in/out, mouse press/release ?
    I think using custom widget i can do this. I ll try this.
    Is stylesheets will work for a flat button ?

    Ok my actual goal is to make something like QtCreater left most widget( widget contain debug,design,edit,project etc).
    So please sugget how to do this.

    Thanks.

  5. #5
    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: disable press effect for QPushButton

    Quote Originally Posted by bibhukalyana View Post
    I dont know about canvas. Is qt 4.7 supports canvas ? Can you please give some example or link ?
    What are other controls which can be used ?
    That's a blind route. fecub is talking about QtQuick which you are not using.

    How I will know paintEvent is called for focus in/out, mouse press/release ?
    You won't and you shouldn't care. paintEvent is called for redrawing the widget and not for other event handlers. It is your responsibility to preserve the state of the widget so that it can be queried in the paintEvent and used to draw the current state of the widget.

    Is stylesheets will work for a flat button ?
    Stylesheets will work for any widget albeit that is not the right tool for this task.

    Ok my actual goal is to make something like QtCreater left most widget( widget contain debug,design,edit,project etc).
    I don't see how you'd obtain this by painting a button red or green. Creator uses a custom style with regular widgets and custom widgets with custom painting. The effect you mention is based on the value of QAbstractButton::checked property.
    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.


  6. #6
    Join Date
    Mar 2011
    Posts
    120
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: disable press effect for QPushButton

    Quote Originally Posted by wysota View Post
    You won't and you shouldn't care. paintEvent is called for redrawing the widget and not for other event handlers. It is your responsibility to preserve the state of the widget so that it can be queried in the paintEvent and used to draw the current state of the widget.
    I didnt get you. Are you telling me to store the present state and paint according to that ?

    Quote Originally Posted by wysota View Post
    I don't see how you'd obtain this by painting a button red or green. Creator uses a custom style with regular widgets and custom widgets with custom painting. The effect you mention is based on the value of QAbstractButton::checked property.
    What I am trying to do is : In left side vertically I want to put some button(any control) and when you click color will change and right side I will load some information.
    It is some thing equivalent to tabWidget.

    Thanks.

  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: disable press effect for QPushButton

    Quote Originally Posted by bibhukalyana View Post
    I didnt get you. Are you telling me to store the present state and paint according to that ?
    Of course.
    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.


  8. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: disable press effect for QPushButton

    Quote Originally Posted by bibhukalyana View Post
    What I am trying to do is : In left side vertically I want to put some button(any control) and when you click color will change and right side I will load some information.
    It is some thing equivalent to tabWidget.

    Thanks.
    Yes, may be you want is a tab widget... search for vertical alignment of tab bars,,, there was an example long back.

    But also as Wysota said,, you could do simpler with buttons with checked state.

Similar Threads

  1. Linux, disable alt+left mouse press drag
    By aftos in forum Qt Programming
    Replies: 0
    Last Post: 21st March 2014, 08:43
  2. Replies: 2
    Last Post: 21st January 2013, 15:02
  3. QPushButton hightlight effect with QStyleSheet
    By franki in forum Qt Programming
    Replies: 0
    Last Post: 23rd September 2012, 16:19
  4. Getting QPushButton to press when embedded in a QFrame.
    By barrygp in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2011, 03:09
  5. Animation effect of gif in QPushButton
    By santosh.kumar in forum Qt Programming
    Replies: 6
    Last Post: 3rd March 2011, 11:14

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.