Results 1 to 2 of 2

Thread: make child widget resizable

  1. #1
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    11
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default make child widget resizable

    I want to make child widgets re-sizable along with the parent. Could you help me ?

    This is my widget constructor:

    Qt Code:
    1. CustomWidget::CustomWidget(QWidget *parent) :
    2. QWidget(parent)
    3. {
    4.  
    5. m_button_edit.setText(tr("Edit"));
    6. m_button_all.setText(tr("All"));
    7. m_button_cancel.setText(tr("Cancel"));
    8.  
    9.  
    10. InitializeModels();
    11.  
    12. m_table1 = new QTableView(this);
    13. m_table2 = new QTableView(this);
    14.  
    15. SetTables();
    16.  
    17. QSplitter *splitter = new QSplitter(Qt::Vertical, this);
    18. splitter->addWidget(m_table1);
    19. QWidget *temp = new QWidget(this);
    20. QGridLayout *layout_table2 = new QGridLayout(this);
    21. layout_table2->addWidget(m_table2, 0, 0, 1, 3);
    22. layout_table2->addWidget(&m_button_edit, 1, 0, 1, 1);
    23. layout_table2->addWidget(&m_button_all, 1, 1, 1, 1);
    24. layout_table2->addWidget(&m_button_cancel, 1, 2, 1, 1);
    25. temp->setLayout(layout_table2);
    26. splitter->addWidget(temp);
    27.  
    28. }
    To copy to clipboard, switch view to plain text mode 

    I got some small window which I should stretch to see the items inside and they have a fixed size.
    If you have any other suggestion about better approach in setting widget positions than in my case I would be glad if you share.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: make child widget resizable

    You need to put a layout on the container widget and add the splitter to it:
    Qt Code:
    1. // at bottom of constructor
    2. QHBoxLayout *lo = new QHBoxLayout(this);
    3. lo->addWidget(splitter);
    4. setLayout(lo);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to ChrisW67 for this useful post:

    mak_user (29th March 2011)

Similar Threads

  1. Widget Resizable Border
    By ale6111 in forum Qt Programming
    Replies: 3
    Last Post: 22nd July 2010, 17:20
  2. Replies: 7
    Last Post: 14th January 2010, 08:47
  3. I need help designing a resizable widget
    By aarelovich in forum Qt Tools
    Replies: 2
    Last Post: 17th February 2009, 18:01
  4. what to do to make windows non-resizable?
    By jamadagni in forum Qt Programming
    Replies: 20
    Last Post: 15th April 2007, 01:32
  5. user resizable and movable QLabel widget
    By hvengel in forum Qt Programming
    Replies: 8
    Last Post: 12th April 2007, 00:01

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.