Results 1 to 12 of 12

Thread: layout's widget does not autofit to window.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    8
    Thanked 133 Times in 128 Posts

    Default Re: layout's widget does not autofit to window.

    can you show some minimal compilable example reproducing the problem

  2. #2
    Join Date
    May 2011
    Posts
    120
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    9

    Default Re: layout's widget does not autofit to window.

    ok

    Qt Code:
    1. button_on = new QPushButton(this);
    2. button_on->setText("ON");
    3. button_on->updateGeometry();
    4. button_on->setMinimumSize(Button_1st_Width, Button_1st_Height);
    5.  
    6. button_off = new QPushButton(this);
    7. button_off->setText("OFF");
    8. //button_off->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    9. button_off->setMinimumSize(Button_1st_Width, Button_1st_Height);
    10.  
    11. button_1st = new QPushButton(this);
    12. button_1st->setText("75%");
    13. button_1st->setMinimumSize(Button_1st_Width, Button_1st_Height);
    14. //button_1st->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    15.  
    16. button_2nd = new QPushButton(this);
    17. button_2nd->setText("50%");
    18. //button_2nd->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    19. button_2nd->setMinimumSize(Button_1st_Width, Button_1st_Height);
    20.  
    21. button_3rd = new QPushButton(this);
    22. button_3rd->setText("50%");
    23. button_3rd->setMinimumSize(Button_1st_Width, Button_1st_Height);
    24.  
    25. button_up_arrow = new QPushButton(this);
    26. button_up_arrow->setMinimumSize(Button_1st_Width, Button_1st_Height);
    27.  
    28. button_down_arrow = new QPushButton(this);
    29. button_down_arrow->setMinimumSize(Button_1st_Width, Button_1st_Height);
    30.  
    31. button_home_profile = new QPushButton("Home Profile", this);
    32. button_home_profile->setMinimumSize(Button_1st_Width, Button_1st_Height);
    33. button_emergency_help = new QPushButton("Emergency Help", this);
    34. button_emergency_help->setMinimumSize(Button_1st_Width, Button_1st_Height);
    35. button_light = new QPushButton("Light", this);
    36. button_light->setMinimumSize(Button_1st_Width, Button_1st_Height);
    37. button_video_phone = new QPushButton("Video Door Phone", this);
    38. button_video_phone->setMinimumSize(Button_1st_Width, Button_1st_Height);
    39. button_custom_control = new QPushButton("Custom Comfort", this);
    40. button_custom_control->setMinimumSize(Button_1st_Width, Button_1st_Height);
    41. button_curtains = new QPushButton("Curtains", this);
    42. button_curtains->setMinimumSize(Button_1st_Width, Button_1st_Height);
    43. ire_label = new QLabel("ireo");
    44. QFont font_ireo("Verdana", 14);
    45. font_ireo.setStretch(QFont::SemiExpanded);
    46. font_ireo.setBold(true);
    47. ire_label->setFont(font_ireo);
    48. ire_label->setMaximumHeight(Button_1st_Height);
    49. ire_label->setAlignment(Qt::AlignCenter);
    50. QFont font1("Verdana", 12);
    51. font1.setStretch(QFont::Expanded);
    52. font1.setBold(true);
    53. room_light_label= new QLabel("Room Light");
    54. room_light_label->setFont(font1);
    55. room_light_label->setAlignment(Qt::AlignCenter);
    56. room_light_label->setMaximumHeight(Button_1st_Height);
    57. gym_light_label= new QLabel("Gym Light");
    58. gym_light_label->setFont(font1);
    59. gym_light_label->setAlignment(Qt::AlignCenter);
    60. gym_light_label->setMaximumHeight(Button_1st_Height);
    61.  
    62. button_on_gym = new QPushButton(this);
    63. button_on_gym->setText("ON");
    64. button_on_gym->setMinimumSize(Button_1st_Width, Button_1st_Height);
    65.  
    66. button_off_gym = new QPushButton(this);
    67. button_off_gym->setText("OFF");
    68. button_off_gym->setMinimumSize(Button_1st_Width, Button_1st_Height);
    69.  
    70. button_1st_gym = new QPushButton(this);
    71. button_1st_gym->setText("75%");
    72. button_1st_gym->setMinimumSize(Button_1st_Width, Button_1st_Height);
    73.  
    74. button_2nd_gym = new QPushButton(this);
    75. button_2nd_gym->setText("50%");
    76. button_2nd_gym->setMinimumSize(Button_1st_Width, Button_1st_Height);
    77.  
    78. button_3rd_gym = new QPushButton(this);
    79. button_3rd_gym->setText("25%");
    80. button_3rd_gym->setMinimumSize(Button_1st_Width, Button_1st_Height);
    81.  
    82. button_up_arrow_gym = new QPushButton(this);
    83. button_up_arrow_gym->setMinimumSize(Button_1st_Width, Button_1st_Height);
    84. button_down_arrow_gym = new QPushButton(this);
    85. button_down_arrow_gym->setMinimumSize(Button_1st_Width, Button_1st_Height);
    86.  
    87. box = new QHBoxLayout();
    88. box->addWidget(button_home_profile);
    89. box->addWidget(button_emergency_help);
    90. box->addWidget(button_light);
    91. box->addWidget(button_video_phone);
    92. box->addWidget(button_curtains);
    93. box->addWidget(button_custom_control);
    94.  
    95. light_frame1 = new QFrame();
    96.  
    97. QGridLayout *grid = new QGridLayout();
    98. grid->setAlignment(Qt::AlignLeft);
    99. grid->setVerticalSpacing(20);
    100. grid->setHorizontalSpacing(50);
    101. grid->setColumnMinimumWidth(0,120);
    102. grid->addWidget(button_1st, 1,1);
    103. grid->addWidget(button_2nd,2,1);
    104. grid->addWidget(button_3rd,3,1);
    105. grid->addWidget(button_up_arrow, 1,2,2,1);
    106. grid->addWidget(button_down_arrow, 2,2,2,1);
    107. grid->setColumnMinimumWidth(3,150);
    108. QGridLayout *gridlayout_gym = new QGridLayout();
    109. gridlayout_gym->setAlignment(Qt::AlignRight);
    110. gridlayout_gym->setVerticalSpacing(20);
    111. gridlayout_gym->setHorizontalSpacing(50);
    112. gridlayout_gym->setColumnMinimumWidth(0,120);
    113. gridlayout_gym->addWidget(button_1st_gym, 1,1);
    114. gridlayout_gym->addWidget(button_2nd_gym,2,1);
    115. gridlayout_gym->addWidget(button_3rd_gym,3,1);
    116. gridlayout_gym->addWidget(button_up_arrow_gym, 1,2,2,1);
    117. gridlayout_gym->addWidget(button_down_arrow_gym, 2,2,2,1);
    118. gridlayout_gym->setColumnMinimumWidth(3,150);
    119. boxlayout_grid->addLayout(grid);
    120. boxlayout_grid->addLayout(gridlayout_gym);
    121. QHBoxLayout *boxlayout_light_label = new QHBoxLayout();
    122. boxlayout_light_label->addWidget(room_light_label);
    123. boxlayout_light_label->addWidget(gym_light_label);
    124. QHBoxLayout *horizontal_layout = new QHBoxLayout();
    125. horizontal_layout->addSpacing(50);
    126. horizontal_layout->addWidget(button_on);
    127. horizontal_layout->addSpacing(100);
    128. horizontal_layout->addWidget(button_off);
    129. horizontal_layout->addSpacing(150);
    130. horizontal_layout->addWidget(button_on_gym);
    131. horizontal_layout->addSpacing(100);
    132. horizontal_layout->addWidget(button_off_gym);
    133. horizontal_layout->addSpacing(110);
    134. QFrame *line = new QFrame();
    135. line->setObjectName(QString::fromUtf8("line"));
    136. line->setGeometry(QRect(320, 150, 118, 3));
    137. line->setFrameShape(QFrame::HLine);
    138. line->setFrameShadow(QFrame::Sunken);
    139. QFrame *line1 = new QFrame();
    140. line1->setObjectName(QString::fromUtf8("line"));
    141. line1->setGeometry(QRect(320, 150, 118, 3));
    142. line1->setFrameShape(QFrame::HLine);
    143. line1->setFrameShadow(QFrame::Sunken);
    144.  
    145. QVBoxLayout *light_vertical_layout = new QVBoxLayout();
    146. light_vertical_layout->addWidget(line1);
    147. light_vertical_layout->addLayout(boxlayout_light_label);
    148. light_vertical_layout->addWidget(line);
    149. light_vertical_layout->addLayout(boxlayout_grid);
    150. light_vertical_layout->addLayout(horizontal_layout);
    151. light_frame1->setLayout(light_vertical_layout);
    152. vertical_layout = new QVBoxLayout();
    153. vertical_layout->addLayout(box);
    154. vertical_layout->addWidget(ire_label);
    155. light_frame1->setVisible(true);
    156. vertical_layout->addWidget(light_frame1);
    157. this->setLayout(vertical_layout);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    8
    Thanked 133 Times in 128 Posts

    Default Re: layout's widget does not autofit to window.

    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?

  4. #4
    Join Date
    May 2011
    Posts
    120
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    9

    Default Re: layout's widget does not autofit to window.

    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.

  5. #5
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    8
    Thanked 133 Times in 128 Posts

    Default Re: layout's widget does not autofit to window.

    Looks like the problem is due to the top buttons. They need that much size because of the text they have to display.

  6. #6
    Join Date
    May 2011
    Posts
    120
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    9

    Default Re: layout's widget does not autofit to window.

    So what i have to do then.

  7. #7
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    8
    Thanked 133 Times in 128 Posts

    Default Re: layout's widget does not autofit to window.

    there can be several ways, but all involve redesigning UI.
    for example, make them as tabs.
    or put the whole thing in a QScrollArea.

  8. #8
    Join Date
    May 2011
    Posts
    120
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    9

    Default Re: layout's widget does not autofit to window.

    Ya this can solve problem, but i have to design ui in the same manner in which i had.Is there any solution then.

  9. #9
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    8
    Thanked 133 Times in 128 Posts

    Default Re: layout's widget does not autofit to window.

    99% of the apps i have seen have different UIs on small screen devices than on desktop.

Similar Threads

  1. Main Window Layout treeview item
    By qwerty1234 in forum Newbie
    Replies: 0
    Last Post: 30th March 2011, 15:41
  2. Replies: 0
    Last Post: 18th January 2011, 16:59
  3. mainwindow layout vs widget layout
    By fatecasino in forum Newbie
    Replies: 2
    Last Post: 14th December 2010, 14:45
  4. How to change a widget to other widget in layout?
    By Kevin Hoang in forum Qt Programming
    Replies: 2
    Last Post: 20th March 2010, 10:55
  5. Window Layout issue.
    By bunjee in forum Qt Programming
    Replies: 0
    Last Post: 26th August 2008, 21:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.