Important: Please read the Qt Code of Conduct -

Screen to fit in desktop as well as Android

  • Hi,

    I have used

     QScreen *sreenWidth   =  qApp->primaryScreen();
     QScreen *screenHeight =  qApp->primaryScreen();
    int width =   sreenWidth->availableSize().width();
    int height =   screenHeight->availableSize().height();

    to get the screen width and height, and i have a header consisting of logo and title.
    I am using the screen width and height to fit both in desktop and android, desktop i am getting fine, but in android i am not getting as expected.
    Here is the header part snippet.

    m_firstWidget = new QWidget;
    m_logoLabel = new QLabel;
    QPixmap officeLogo;
    m_titleLabel = new QLabel;
    m_titleLabel->setStyleSheet("font:bold;  font-size:30px; color: white; background-color:#B21216");
    m_closeButton = new QPushButton;
    QPixmap closePixMap(":/new/prefix1/images/closebuttonlogo.png");
    QIcon closeButtonIcon(closePixMap);
    QSize size(m_closeButton->width(),m_closeButton->height());
    m_hbox = new QHBoxLayout(m_firstWidget);

    I have taken widget and setting parent for layout consisting of label and title label and close button. how can i get the approach right.? even for android.

    Guidance is required,

  • Lifetime Qt Champion


    AFAIK, on Android you only have fullscreen available.

    By the way, why are you doing such math in your application ?

  • Because developing the android application maintaining the header label as separate class and calling the headerLabel class by other classes.

  • Lifetime Qt Champion

    I fail to see how calling your HeaderLabel class from several place is related to these maths.

    Looking at how you customize things, why not consider QML for your application ? Especially on Android.

  • i am using header label as i require for my application and for each widgets their is the same label, so i have a separate class called headerLabel, to use as code reuseablilty, instead of having the headerlabel in all classes.

  • Lifetime Qt Champion

    In that case you could even have a "base widget" that already contains that label (a bit like a QWizardPage) and then only your other widgets in it (a bit like QMainWindow and its central widget).

    But still, having just hardcoded values in the constructor isn't right, at construction time no definite size is known. You should rather use the stretch factors of the layout to distribute the space nicely between your widgets.

Log in to reply