Jakube
Jakube

Reputation: 3575

Qt Scale image after maximizing window

I want to change the image scale depending on the size of the qgraphicsview.

My current code scales the image, if the window is re-sized, but not if the window is maximized.

bool EnlargedView::eventFilter(QObject *object, QEvent *event)
{
    if (ui.graphicsView == object && (event->type() == QEvent::WindowStateChange || event->type() == QEvent::Resize)) {
        scalePicture();
    }
    return QWidget::eventFilter(object, event);
}

I think it is because of the event WindowStateChange is called, when the maximize button is clicked, and not after the window is maximized (which happens later).

Any ideas, how to scale the image after maximization?

Upvotes: 1

Views: 492

Answers (1)

mattking
mattking

Reputation: 143

Use QWidget::resizeEvent http://qt-project.org/doc/qt-4.8/qwidget.html#resizeEvent

It gets called after the new geometry is set so you will have the correct geometry to scale with.

Upvotes: 2

Related Questions