Results 1 to 5 of 5

Thread: Button in Layout help

  1. #1
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Button in Layout help

    Hi,

    I'am having a problem in my code. I used addSpacing() and SeFixedSized(), to fix the buttons in my code. But the problem is once i enlarge the window, the buttons stay the same size and they dont get bigger with the same ratio as the window. I would appreciate any assistance on how i can fix this problem.

    This is my code:

    Qt Code:
    1. #include <QLabel>
    2. #include <QPushButton>
    3. #include <QProgressBar>
    4. #include <QLineEdit>
    5. #include <QIcon>
    6. #include <QHBoxLayout>
    7. #include <QVBoxLayout>
    8. #include <QToolButton>
    9. #include <QApplication>
    10. #include "auto.h"
    11.  
    12. Auto::Auto(QWidget *parent) : QWidget(parent)
    13. {
    14. // Title of the window
    15. this->setWindowTitle("Main Menu");
    16. this->resize(500, 350); // I'm using your old values
    17.  
    18. b_start = new QPushButton(tr("START/STOP"));
    19. b_exit = new QPushButton(tr("Exit"));
    20.  
    21.  
    22. b_start->setFixedSize(70,30);
    23. b_exit->setFixedSize(50,30);
    24.  
    25. l_welcome = new QLabel(tr("--Automatic Interface--"));
    26. l_welcome->setFont(QFont("Times", 18, QFont::Bold));
    27.  
    28.  
    29. l_welcome->setAlignment(Qt::AlignCenter);
    30.  
    31. l_load = new QLabel(tr("Load Images"));
    32. l_load->setFont(QFont("Times", 12, QFont::Bold));
    33.  
    34. l_load->setAlignment(Qt::AlignLeft);
    35.  
    36. t_text = new QLineEdit(this);
    37. t_text->setFixedSize(150,20);
    38. t_browse = new QToolButton(this);
    39. p_prog = new QProgressBar(this);
    40. p_prog->setFixedSize(100,20);
    41. v_1->setAlignment(Qt::AlignLeft);
    42.  
    43. v_1->addWidget(l_load);
    44. v_1->addSpacing(10);
    45. v_1->addWidget(t_text);
    46. v_1->addWidget(t_browse);
    47. v_1->addSpacing(20);
    48. v_1->addWidget(p_prog);
    49.  
    50. v_2->setAlignment(Qt::AlignCenter);
    51.  
    52. v_2->addWidget(b_start);
    53. v_2->addWidget(b_exit);
    54.  
    55. QVBoxLayout *layout_vert = new QVBoxLayout;
    56. layout_vert->setAlignment(Qt::AlignCenter);
    57.  
    58. layout_vert->addWidget(l_welcome);
    59. layout_vert->addSpacing(30);
    60. layout_vert->addLayout(v_1);
    61. layout_vert->addSpacing(30);
    62. layout_vert->addLayout(v_2);
    63.  
    64.  
    65. this->setLayout(layout_vert);
    66.  
    67. }
    To copy to clipboard, switch view to plain text mode 

    Thanks!!
    Last edited by IsleWitch; 9th October 2007 at 14:57.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Button in Layout help

    First of all get rid of all size fixing. From what I understand your widget looks like the form in the attachment (apart from the fonts of course), is that correct?

    Now you have to decide which widgets should change their size when you resize the dialog and where there should be additional space when the widget is resized.Take the widget from attachment and add spacers everywhere you want additional space to be located when you resize the widget and change size policies of widgets you wish to expand to minimumExpanding. Then preview the form and see if that's what you want to get. If not, correct and try again.
    Attached Files Attached Files

  3. #3
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Button in Layout help

    The Main problem is that i wasnt able to change the buttons in the size i want them, so i used the setfixedsize() function which gave me another problem on resizing the window. so is there a way to set the size of the buttons without using the setfixedsize() function??

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Button in Layout help

    In what way do you want to change the button size? At worst you'll have to subclass and reimplement sizeHint() but I'm almost sure you can achieve the effect you want by tweaking the properties appropriately (namely by adjusting the size policy).

  5. #5
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Button in Layout help

    well, it turned out that its better keeping them the same size, i'll just have to worry about having them in the right places, i guess a couple of spaces would do it.

    thanks alot for ur help

Similar Threads

  1. changing layout of a widget
    By mikro in forum Qt Programming
    Replies: 10
    Last Post: 4th August 2009, 21:21
  2. Qt layout memory issue
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 25th August 2007, 18:11
  3. problem with Tool button n Layout
    By arjunasd in forum Qt Tools
    Replies: 11
    Last Post: 24th July 2007, 22:14
  4. Resizing problems when applying a layout
    By JimBrown in forum Newbie
    Replies: 1
    Last Post: 21st February 2007, 23:54
  5. Layout issues
    By vijay anandh in forum Qt Programming
    Replies: 2
    Last Post: 8th July 2006, 20:27

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.