W
W
whoami?root root_toor2016-04-16 23:57:53
Qt
whoami?root root_toor, 2016-04-16 23:57:53

Qt Widgets how to color only one widget?

Hello!
Question: There is one large field where I insert my widgets - different amount, depending on the data.
The rendering takes place in an overridden paintEvent.
You just need to implement the choice of one widget from all the others.
More specifically, I have a flag in the widget:
bool isActive;
Further overridden events:

void Widget::focusOutEvent(QFocusEvent *event)
{
    isActive = false;
}
void Widget::mousePressEvent(QMouseEvent *event)
{
    isActive = true;
    if(event->type() == QEvent::WindowDeactivate) isActive = false;
    this->update();
}

Accordingly, when the widget is clicked, the isActive flag is set, drawing in paintEvent takes place depending on this flag. Zer good)
And how now to remove the selection of the widget when clicking on another widget?
The focusOutEvent event does not fire (although I also tried setting setFocus(), setWindowFlags(Qt::Tool) in the constructor and calling focusWidget()).
There is also a changeEvent ... but there are all events, and here they are already filtered ... in general, how to be?
In general, how is such a task solved, through focus - events? Why don't they come then?
Should this task be solved event-wise, without saving the state of all widgets!?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
whoami?root root_toor, 2016-04-17
@1q2w1q2w

Damn) as usual, everything is banal) forgot to call the update () method :)

bool Widget::eventFilter(QObject *object, QEvent *event)
{
    if (event->type() == QEvent::FocusOut)
    {
        if (object == this)
        {
            qDebug() << "Здесь ловим событие focus Out!";
            this->isActive = false;
            this->update();    // из-за этой строчки я потерял 1,5 часа)
        }
    }
    return false;
}

And all because I thought that paintEvent was already called 100 times per second, update () is not needed)) Ha .. needed! Only through the debugger could I catch ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question