Refresh QPushButton with mouse position
-
Here's a preview of what's happening:
!https://dl.dropbox.com/s/hw925d952uj41hm/button.gif(button)!
Here's the code I am using when the window is closing, trying to clear the button's focus (doesn't work, as you can see)
@void ConfigureWindow::closeEvent(QCloseEvent *event)
{
event->ignore();
m_titlebar->buttonClose->clearFocus();
this->hide();
}@ -
The QWidget::onClose() event is not triggered when you hide a widget. Instead,the "QWidget::onHide()":http://qt-project.org/doc/qt-5/qwidget.html#hide event is triggered. Put your code in this event and try again :-)
-
It is triggered. Here's what buttonClose does:
@connect( buttonClose, SIGNAL( clicked() ), parent, SLOT( close() ) );@
Just to make sure, I've placed a display message box code to see if it really got executed -> it did.
As you can see in the code posted below, I am ignoring close event, and instead I call this->hide() from there.
-
The main issue is still the same, the button does not have a chance to loose focus before the window is hidden.
As a workaround, can you move focus on another object before hiding? -
I probably could, but I don't quite understand why it doesn't have a chance to lose focus before the window is hidden.
@m_titlebar->buttonClose->clearFocus();
this->hide();@this kinda gives it the chance, no? Or does it have to be inside onHide event? (the clearFocus)
-
I think the problem there is not focus at all, but actually, the widget painting. Seems like after hiding, closing or minimizing a widget, the paint event just stops drawing.
consider this simple code:
@#include <QApplication>
#include <QWidget>
#include <QPushButton>int main(int argc, char *argv[]){
QApplication a(argc, argv);QPushButton button;
button.resize(200, 100);
button.show();QObject::connect(&button, SIGNAL(clicked()), &button, SLOT(showMinimized()));
return a.exec();
}@
When you press the button it will minimize the window. As you click on the icon in the taskbar the window is restored and the button looks normal. but if you look at the taskbar preview you can see the window is still painted with the pressed button state (right side of the image).
!http://img.networkdigitale.com/di/0ZRM/preview.png(preview)!I don't have a solution, but I may suggest to force repaint the widget by calling the painter or something....
-
Right, now tell me this isn't Qt's fault that there is no clear way to fix this, or even that it happens at all.
I've tried to repaint the widget, but it didn't work.
-
you can write a bug about this.. for sure the developers will want to get rid of it in Qt 5.4. Indeed is looking like a bug - or maybe an optimisation for low memory... hm.. who know... but any way some window flags suppose to be to repaint before hiding or on showing. any way for me this is a strange behaviour.
-
I don't think it's literally a bug. When an object is hidden it doesn't make sense to try drawing it because there is nothing to be shown to the user. Altough, the fact that an object is not correctly updated when restoring it, might be a qt issue. You should check this more thoroughly, see if there is something in your code that causes this behavior. I'm sure it would have been noticed by more people if it was a qt issue.
The pushbutton object you're using, is it a custom class derived from QPushButton? If so, can you share the code so people can check it?
-
It's a QPushButton with CSS style applied.
-
I've fixed it by doing this:
@void ConfigureWindow::closeEvent(QCloseEvent *event)
{
event->ignore();
// You have to completely remove the widget, add it again and wait about 10ms, then hide window
// to clear hover state on the close button nicely.
m_titlebar->HideTitlebar(); // this removes and deletes all buttons
m_titlebar->DisplayTitlebar(); // this initializes and adds them again
QTimer::singleShot(10, this, SLOT(finalizeClose()));
}void ConfigureWindow::finalizeClose()
{
this->hide();
}@This is an awkward, but working solution.