Get method
First look at a program code:
int main(int*argv[]){ QApplication a(argc, argv); Dialog w; w.show(); return a.exec();}
A is an application, W is a dialog box; we get the screen size, we need to get it from variable A;
QScreen *iScreen = a.primaryScreen(); QSize rScreenSize = iScreen->size();
Although the screen size is obtained, but we change the UI size of the program in dialog w, this time we need to overload dialog, will get the size of the incoming dialog inside, first in the header file Dialog.h to modify the following code
public QDialog{ Q_OBJECTpublic: explicitDialog0); ~Dialog();private: Ui::Dialog *ui;};
Change the code above to
public QDialog{ Q_OBJECTpublic: explicitDialog(int iWidth,int0); ~Dialog();private: Ui::Dialog *ui; int width; int height;};
Also, modify the Dialog.cpp to
Dialog::Dialog*parent) : QDialog(parent), ui(new Ui::Dialog){ = iWidth; = iHeight-50; ui->setupUi(this); this->setFixedSize(width,height); //......}
OK, this can be achieved, the program window adapts to the screen size, but there is a drawback: all the space added in the form must change as the form changes, which may lead to more cumbersome and complex program development.
How Qt for Android gets the phone screen size