Greetings. I just found out that I'm doing everything wrong ... I have all the sizes of the dialogs in pixels, but I need a percentage of the screen size. Climbed all Qt Designer, did not find such settings. How to do it? I have Qt version 5.5.1.

  • There are no such settings. As a percentage of screen size, dimensions cannot be set. But you can determine the screen size and when displaying the dialog, change its size. - user194374

2 answers 2

Add to widget constructor.

#define PERCENT_OF_SCREEN (25 / 100) QRect r = QApplication::desktop()->screenGeometry(); this->resize(r.width() * PERCENT_OF_SCREEN, r.height() * PERCENT_OF_SCREEN); 

here (25 / 100) first number is the size of the widget as a percentage of the screen size.

  • In a question about the designer it is, apparently. - free_ze
  • And you know that screenGeometry gets all the total resolution, including permissions from other screens. - Vyacheslav Savchenko
  • You need to use this: QRect *screenRect = QApplication::screens().at(0)->geometry(); , just #include <QScreen> do it. - Vyacheslav Savchenko
  • @ VyacheslavSavchenko In the documentation, there is no such "Returns the screen with the index screen. The default screen is -1 if the screen is -1." - Inline
  • This I wrote is not too clear. This is really about the size of the fonts, about the designer and about the wrong sizes in pixels. Layout does not help, it is only inside the form. The answer can be accepted, I do not just need a designer. I will consider remarks. Thank you all. I still have one screen, up to Qt 5.6, the application is the default Application DPI-Aware, the scale is determined for the whole application, and there is another rake - it’s not clear where to get the scale factor, but I understand. - Ilya Ivanov

In my opinion, specifying some specific and even relative sizes to widgets is not very correct. In Qt, there is absolutely everything so that later it would not be excruciatingly painful for the crookedly chosen coordinates or percentage factors, if the program is running on the screen with alternative settings, such as enlarged fonts and the like. It is better to let placement managers ( QLayout ) adjust the size of the dialogs themselves so that the user interface looks neat in any case.