I wrote a program and completely forgot that not all screens have such a high resolution. When you open on a small screen resolution half of the program is not visible. How this is solved by the example of qt at least approximately. The main work of the program in mainwindow (maximized) all widgets are very tight. Can make two different windows mainwindow and check for monitor size? How correct?
- Two may be few. Create a Grid Layout to conveniently change the size of the window and throw your widgets there. Read the current screen size and make on 3/4 screen. The only thing that will need to adjust the stretching of widgets under different screens is that there would be fewer spaces. - Tony Estakado
- thank. There is something to think about!) - Alexey Smirnov
|
1 answer
QRect screenRect(QApplication::desktop()->screenGeometry()); And relative to the current screen size, adjust the size of the interface.
For example, this is how Telegram Desktop does it :
void MainWindow::psInitSize() { setMinimumWidth(st::wndMinWidth); setMinimumHeight(st::wndMinHeight); TWindowPos pos(cWindowPos()); QRect avail(QDesktopWidget().availableGeometry()); // <--------<<< bool maximized = false; QRect geom( avail.x() + (avail.width() - st::wndDefWidth) / 2, avail.y() + (avail.height() - st::wndDefHeight) / 2, st::wndDefWidth, st::wndDefHeight); if (pos.w && pos.h) { QList<QScreen*> screens = Application::screens(); for (auto i = screens.cbegin(), e = screens.cend(); i != e; ++i) { QByteArray name = (*i)->name().toUtf8(); if (pos.moncrc == hashCrc32(name.constData(), name.size())) { QRect screen((*i)->geometry()); int32 w = screen.width(), h = screen.height(); if (w >= st::wndMinWidth && h >= st::wndMinHeight) { if (pos.w > w) pos.w = w; if (pos.h > h) pos.h = h; pos.x += screen.x(); pos.y += screen.y(); if (pos.x < screen.x() + screen.width() - 10 && pos.y < screen.y() + screen.height() - 10) { geom = QRect(pos.x, pos.y, pos.w, pos.h); } } break; } } if (pos.y < 0) pos.y = 0; maximized = pos.maximized; } setGeometry(geom); } |