PDA

View Full Version : layout's widget does not autofit to window.



Niamita
19th October 2011, 07:54
Hi everyone

When i run my program on tablet, the layout of the window does not autofit to the tablet screen.
Layout does not get enlarge or shrink, while on pc it is fine as desire. I set the layou's widget size by setMinimumSize() in the ratio of device's screen width or height. i also tried to solve this by setting sizepolicy() but i does not get desire output on tablet.

One more think shall i have to set widget's stylesheet according to the screen resolution individualy.
Please help me, i am working on this since 1 and half day, but i am not successfull in getting the desire display on tablet.

nish
19th October 2011, 09:00
are you talking about internal layout of widgets in your window or the window itself. For the latter case, have you tried showFullScreen(), showMaximised()?

Niamita
19th October 2011, 09:05
i am talking about internal layout in window.

nish
19th October 2011, 09:28
can you show some minimal compilable example reproducing the problem

Niamita
19th October 2011, 09:37
ok


button_on = new QPushButton(this);
button_on->setText("ON");
button_on->updateGeometry();
button_on->setMinimumSize(Button_1st_Width, Button_1st_Height);

button_off = new QPushButton(this);
button_off->setText("OFF");
//button_off->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
button_off->setMinimumSize(Button_1st_Width, Button_1st_Height);

button_1st = new QPushButton(this);
button_1st->setText("75%");
button_1st->setMinimumSize(Button_1st_Width, Button_1st_Height);
//button_1st->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

button_2nd = new QPushButton(this);
button_2nd->setText("50%");
//button_2nd->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
button_2nd->setMinimumSize(Button_1st_Width, Button_1st_Height);

button_3rd = new QPushButton(this);
button_3rd->setText("50%");
button_3rd->setMinimumSize(Button_1st_Width, Button_1st_Height);

button_up_arrow = new QPushButton(this);
button_up_arrow->setMinimumSize(Button_1st_Width, Button_1st_Height);

button_down_arrow = new QPushButton(this);
button_down_arrow->setMinimumSize(Button_1st_Width, Button_1st_Height);

button_home_profile = new QPushButton("Home Profile", this);
button_home_profile->setMinimumSize(Button_1st_Width, Button_1st_Height);
button_emergency_help = new QPushButton("Emergency Help", this);
button_emergency_help->setMinimumSize(Button_1st_Width, Button_1st_Height);
button_light = new QPushButton("Light", this);
button_light->setMinimumSize(Button_1st_Width, Button_1st_Height);
button_video_phone = new QPushButton("Video Door Phone", this);
button_video_phone->setMinimumSize(Button_1st_Width, Button_1st_Height);
button_custom_control = new QPushButton("Custom Comfort", this);
button_custom_control->setMinimumSize(Button_1st_Width, Button_1st_Height);
button_curtains = new QPushButton("Curtains", this);
button_curtains->setMinimumSize(Button_1st_Width, Button_1st_Height);
ire_label = new QLabel("ireo");
QFont font_ireo("Verdana", 14);
font_ireo.setStretch(QFont::SemiExpanded);
font_ireo.setBold(true);
ire_label->setFont(font_ireo);
ire_label->setMaximumHeight(Button_1st_Height);
ire_label->setAlignment(Qt::AlignCenter);
QFont font1("Verdana", 12);
font1.setStretch(QFont::Expanded);
font1.setBold(true);
room_light_label= new QLabel("Room Light");
room_light_label->setFont(font1);
room_light_label->setAlignment(Qt::AlignCenter);
room_light_label->setMaximumHeight(Button_1st_Height);
gym_light_label= new QLabel("Gym Light");
gym_light_label->setFont(font1);
gym_light_label->setAlignment(Qt::AlignCenter);
gym_light_label->setMaximumHeight(Button_1st_Height);

button_on_gym = new QPushButton(this);
button_on_gym->setText("ON");
button_on_gym->setMinimumSize(Button_1st_Width, Button_1st_Height);

button_off_gym = new QPushButton(this);
button_off_gym->setText("OFF");
button_off_gym->setMinimumSize(Button_1st_Width, Button_1st_Height);

button_1st_gym = new QPushButton(this);
button_1st_gym->setText("75%");
button_1st_gym->setMinimumSize(Button_1st_Width, Button_1st_Height);

button_2nd_gym = new QPushButton(this);
button_2nd_gym->setText("50%");
button_2nd_gym->setMinimumSize(Button_1st_Width, Button_1st_Height);

button_3rd_gym = new QPushButton(this);
button_3rd_gym->setText("25%");
button_3rd_gym->setMinimumSize(Button_1st_Width, Button_1st_Height);

button_up_arrow_gym = new QPushButton(this);
button_up_arrow_gym->setMinimumSize(Button_1st_Width, Button_1st_Height);
button_down_arrow_gym = new QPushButton(this);
button_down_arrow_gym->setMinimumSize(Button_1st_Width, Button_1st_Height);

box = new QHBoxLayout();
box->addWidget(button_home_profile);
box->addWidget(button_emergency_help);
box->addWidget(button_light);
box->addWidget(button_video_phone);
box->addWidget(button_curtains);
box->addWidget(button_custom_control);

light_frame1 = new QFrame();

QGridLayout *grid = new QGridLayout();
grid->setAlignment(Qt::AlignLeft);
grid->setVerticalSpacing(20);
grid->setHorizontalSpacing(50);
grid->setColumnMinimumWidth(0,120);
grid->addWidget(button_1st, 1,1);
grid->addWidget(button_2nd,2,1);
grid->addWidget(button_3rd,3,1);
grid->addWidget(button_up_arrow, 1,2,2,1);
grid->addWidget(button_down_arrow, 2,2,2,1);
grid->setColumnMinimumWidth(3,150);
QGridLayout *gridlayout_gym = new QGridLayout();
gridlayout_gym->setAlignment(Qt::AlignRight);
gridlayout_gym->setVerticalSpacing(20);
gridlayout_gym->setHorizontalSpacing(50);
gridlayout_gym->setColumnMinimumWidth(0,120);
gridlayout_gym->addWidget(button_1st_gym, 1,1);
gridlayout_gym->addWidget(button_2nd_gym,2,1);
gridlayout_gym->addWidget(button_3rd_gym,3,1);
gridlayout_gym->addWidget(button_up_arrow_gym, 1,2,2,1);
gridlayout_gym->addWidget(button_down_arrow_gym, 2,2,2,1);
gridlayout_gym->setColumnMinimumWidth(3,150);
boxlayout_grid->addLayout(grid);
boxlayout_grid->addLayout(gridlayout_gym);
QHBoxLayout *boxlayout_light_label = new QHBoxLayout();
boxlayout_light_label->addWidget(room_light_label);
boxlayout_light_label->addWidget(gym_light_label);
QHBoxLayout *horizontal_layout = new QHBoxLayout();
horizontal_layout->addSpacing(50);
horizontal_layout->addWidget(button_on);
horizontal_layout->addSpacing(100);
horizontal_layout->addWidget(button_off);
horizontal_layout->addSpacing(150);
horizontal_layout->addWidget(button_on_gym);
horizontal_layout->addSpacing(100);
horizontal_layout->addWidget(button_off_gym);
horizontal_layout->addSpacing(110);
QFrame *line = new QFrame();
line->setObjectName(QString::fromUtf8("line"));
line->setGeometry(QRect(320, 150, 118, 3));
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
QFrame *line1 = new QFrame();
line1->setObjectName(QString::fromUtf8("line"));
line1->setGeometry(QRect(320, 150, 118, 3));
line1->setFrameShape(QFrame::HLine);
line1->setFrameShadow(QFrame::Sunken);

QVBoxLayout *light_vertical_layout = new QVBoxLayout();
light_vertical_layout->addWidget(line1);
light_vertical_layout->addLayout(boxlayout_light_label);
light_vertical_layout->addWidget(line);
light_vertical_layout->addLayout(boxlayout_grid);
light_vertical_layout->addLayout(horizontal_layout);
light_frame1->setLayout(light_vertical_layout);
vertical_layout = new QVBoxLayout();
vertical_layout->addLayout(box);
vertical_layout->addWidget(ire_label);
light_frame1->setVisible(true);
vertical_layout->addWidget(light_frame1);
this->setLayout(vertical_layout);

nish
19th October 2011, 11:32
well it works for me on desktop. what happens of tablet? does it fills the entire screen or some part of it? how do you resize it on tablet?

Niamita
19th October 2011, 11:40
i am not resizing it on tablet, when i run it on tablet the layout does not fit to tablet screen, some part of designed layout get cut.

nish
19th October 2011, 11:45
Looks like the problem is due to the top buttons. They need that much size because of the text they have to display.

Niamita
19th October 2011, 12:09
So what i have to do then.

nish
19th October 2011, 13:53
there can be several ways, but all involve redesigning UI.
for example, make them as tabs.
or put the whole thing in a QScrollArea.

Niamita
19th October 2011, 14:01
Ya this can solve problem, but i have to design ui in the same manner in which i had.Is there any solution then.

nish
19th October 2011, 14:09
99% of the apps i have seen have different UIs on small screen devices than on desktop.