PDA

View Full Version : disable press effect for QPushButton



bibhukalyana
25th September 2014, 13:47
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.

fecub
25th September 2014, 20:23
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.

wysota
25th September 2014, 23:28
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.

bibhukalyana
26th September 2014, 06:09
Thanks for reply.



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 ?


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.

wysota
26th September 2014, 09:44
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.

bibhukalyana
26th September 2014, 10:06
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 ?



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.

wysota
26th September 2014, 17:01
I didnt get you. Are you telling me to store the present state and paint according to that ?

Of course.

aamer4yu
30th September 2014, 10:01
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.