PDA

View Full Version : Why are my QPushButtons slowly "blinking"?



davethomaspilot
10th February 2013, 01:52
I have a Dialog with a GroupBox that contains several checkable QPushButtons that are not mutually exclusive.

When the dialog is first shown, the background of the top button in the group slowly (cycle time a couple of seconds) changes from grey/white to light blue. When I click the button to make it "checked" the background stays solid blue (maybe slightly darker).

Checking some (but not all) of the other buttons in the group box will stop the unchecked top button from blinking. When I check a button and uncheck it, that button stays blinking until I check another button.

I don't want this behavior, since it make it hard to see a checked button versus one that's doing its blinky thing.

I'm sure this is a newbie question, but I've read QPushButton documentation and can't figure out what's going on.

The issue may be related to what I've set for icons. I have a "Normal On" icon defined for the top two buttons. That seems to create slightly different shading of the icon image for Normal Off, Disabled Off, Disabled on, active off, and active on. Interestingly, when I check the second button (which has an icon image) that doesn't stop the top button blinking. But checking the buttons that don't have an icon image causes the top button to stop blinking.

I don't see this in Qt Designer Preview. It behaves just like I want in Designer--no blinking thing, the buttons highlight when I mouse over them, but they immediately go back to their original shading when the mouse moves off of them.

What's going on? Where can I find documentation that explains?

Hopefully, I don't have to create a slightly different version of the icon, shaded differently, for each of the states?

Thanks,

Dave Thomas

Added after 1 2 minutes:

I don't know why it was behaving the way it was, but I got what I want by setting focusPolicy to "NoFocus" in Qt designer.

I understand about setting styles for each of the button states, eg. background. But I still don't understand the blinky thing. So, while I have a workaround, I'd like to understand better.

Thanks,

Dave Thomas

ChrisW67
10th February 2013, 21:55
This does not do what you describe for me on Linux:


#include <QtGui>

class Widget: public QGroupBox {
Q_OBJECT
public:
Widget(QWidget *p = 0): QGroupBox("Test", p)
{
QVBoxLayout *layout = new QVBoxLayout(this);
for (int i = 0; i < 5; ++i) {
QPushButton *p = new QPushButton(this);
p->setCheckable(true);
layout->addWidget(p);
}
setLayout(layout);
}
};

int main(int argc, char **argv)
{
QApplication app(argc, argv);
Widget w;
w.show();
return app.exec();
}
#include "main.moc"



What's going on? Where can I find documentation that explains? If setting Qt::NoFocus on the buttons changes the behaviour then it seems likely the behaviour is related to keyboard focus. Given it is a QDialog this is likely related to default and autodefault buttons on the dialog