Unsolved 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_firstWidget->setFixedSize(width,height/4); m_firstWidget->setStyleSheet("background-color:#B21216"); m_logoLabel = new QLabel; m_logoLabel->setFixedSize(m_firstWidget->width()/14,m_firstWidget->height()/1.5); m_logoLabel->setStyleSheet("background-color:#B21216"); QPixmap officeLogo; officeLogo.load(":/new/prefix1/images/logo.png"); m_logoLabel->setPixmap(officeLogo.scaled(m_logoLabel->width(),m_logoLabel->height())); m_titleLabel = new QLabel; m_titleLabel->setFixedSize(m_firstWidget->width()/1.5,m_firstWidget->height()/1.5); m_titleLabel->setText("Title"); m_titleLabel->setStyleSheet("font:bold; font-size:30px; color: white; background-color:#B21216"); m_closeButton = new QPushButton; m_closeButton->setFixedSize(m_firstWidget->width()/14,m_firstWidget->height()/1.5); m_closeButton->setStyleSheet("background-color:#B21216"); QPixmap closePixMap(":/new/prefix1/images/closebuttonlogo.png"); QIcon closeButtonIcon(closePixMap); QSize size(m_closeButton->width(),m_closeButton->height()); m_closeButton->setIcon(closeButtonIcon); m_closeButton->setIconSize(size); m_hbox = new QHBoxLayout(m_firstWidget); m_hbox->addWidget(m_logoLabel); m_hbox->addWidget(m_titleLabel); m_hbox->addWidget(m_closeButton);
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,
Thanks, -
Hi,
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.
-
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.
-
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.