PDA

View Full Version : QPushButton not calling repaint when needed?



Enygma
30th August 2007, 15:55
Me again :p

I`m just trying to find out if this is a bug or not :)

Ok, here it goes:

I have QPushButtons on a QFrame and a stylesheet for the buttons for the normal state and the :hover state, the last adding a border-image to the button.


QPushButton {
image: url(:/images/userLocation.png);
image-position: center center;
border-image: url();
}
QPushButton:hover {
border-image: url(:/images/button_active.png);
}

All goes well untill I add a popup as a CustomContextMenu to the buttons, called with the customContextMenuRequested( const QPoint & ) signal.

When the popup is called, it shows correctly but if I right-click on another one of these buttons, the popup goes away as it should, the second button gets hovered and the border-image is applied to it, but the first button never gets to unset it's border-image, and come back to it's display it should have when not hovered.
In other words, i end up with two hovered-looking buttons.

If I repeat the process and right click on the QFrame this time, it's the same thing, they both remain hovered, menu is gone.

If I leave the QFrame with the mouse, the buttons get reset and go back to their normal look.

After trying different approaches I tried giving the QPushButton that requested a context menu a repaint right when the popup is aboutToHide().

It worked! Now when the popup hides, the old right-clicked QPushButton looks normal.

Is this normal? Shouldn't this repaint get called automatically? That would sound logical to me.

P.S.: I use a QPushButton* to remember which button requested a context menu, maybe qt doesn't and there for, does not know where to call repaint? :confused:

Cheers!

jpn
3rd September 2007, 21:22
By the way, QToolButton has built-in menu support. :)

Enygma
3rd September 2007, 21:38
Sorry, I don`t follow, what kind of menu support do you mean?

And the context in which I`m using this is a QFrame having some buttons on it.

jpn
3rd September 2007, 21:55
You know, QToolButton can show a menu in three different ways; either with or without a delay or by pressing a special menu indicator. I just mean that this might be a bit more intuitive than using standard context menu which is quite rarely used for buttons I think. My apologies if this does not fit to the context. This was just a suggestion. ;)

As for the original problem, have you tried to examine the even flow? Does the problematic button for example ever receive a leave event? Try installing a few event filters and printing events and receivers to debug output.

Enygma
3rd September 2007, 22:08
Thanks a lot for all the prompt responses ;)

Now, about this issue... I`ve already put it behind me... just called that repaint and did the job, I definitely think that the focusOut is not being fired there but I don't know when I`ll have the time or patience to test it again.

And about the menu possibilities of QPushButton, thanx for the suggestions, I`ll give it a look, although the context menu seemed a straightforward approach :p :rolleyes:

Cheers.

srinirao
13th May 2010, 17:03
Try setting Qt::WA_OpaquePaintEvent widget attribute for PushButton. It worked for me !!