Force aspect ratio on window
Unsolved
General and Desktop
-
I have a second dialog style window which is started in mainwindow.cpp like this:
externalDisplay = new ExternalDisplay(this);
externalDisplay->show();
I want to allow resizing that window but the aspect ratio must not change. I tried using event filters like this:ExternalDisplay::ExternalDisplay(QWidget *parent) : QDialog(parent), ui(new Ui::ExternalDisplay) { ui->setupUi(this); this->installEventFilter(this); } bool ExternalDisplay::eventFilter(QObject* obj, QEvent* event) { if (event->type() == QEvent::Resize) { QResizeEvent* resizeEvent = static_cast<QResizeEvent*>(event); qDebug() << "Window resized to: " << resizeEvent->size(); int newWidth = resizeEvent->size().width(); int newHeight = (5 * newWidth) / 7; this->resize(newWidth, newHeight); } return false; }
I want the aspect ratio to be 7/5 but with this solution the window is flickering because it keeps changing between the users input and the forced aspect ratio. Is there a better solution?
-
all I think off is actually not resize the window while the user is resizing it but visualize it only and only resize the window/dialog once after the resize operation stops.