How Qt for Android gets the phone screen size

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.