Also since paintEvent() gets called so often, you could put any tests & update() in a slot:
{
...
}
Q_UNUSED(old);
if(QString(now
->metaObject
()->className
())=="QLineEdit") _brush.
setColor(Qt
::red);
else _brush.setColor(Qt::blue);
update();
}
Q_UNUSED(event);
painter.begin(this);
painter.fillRect(rect(), _brush);
painter.end();
}
Widget::Widget(QWidget *parent) :
QWidget(parent), _brush(Qt::red)
{
...
connect(qApp,SIGNAL(focusChanged(QWidget*,QWidget*)),this,SLOT(changedFocus(QWidget*,QWidget*)));
}
void Widget::changedFocus(QWidget *old,QWidget *now){
Q_UNUSED(old);
if(QString(now->metaObject()->className())=="QLineEdit") _brush.setColor(Qt::red);
else _brush.setColor(Qt::blue);
update();
}
void Widget::paintEvent ( QPaintEvent * event ) {
Q_UNUSED(event);
QPainter painter;
painter.begin(this);
painter.fillRect(rect(), _brush);
painter.end();
}
To copy to clipboard, switch view to plain text mode
Bookmarks