Results 1 to 5 of 5

Thread: QSplitter and QTableWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QSplitter and QTableWidget

    Hi. I have a QSplitter widget separating two QTableWidget instances.
    I want each table to stretch to its area's dimension. Meaning I want the tables to occupy all the space available to them.
    How do I achieve that?

    Qt Code:
    1. table1 = new QTableWidget(splitter);
    2. table2 = new QTableWidget(splitter);
    3. splitter->addWidget(table1);
    4. splitter->addWidget(table2);
    To copy to clipboard, switch view to plain text mode 

    When I pull the handle of the qsplitter, I want the tables to stay stretched to maximum, just like the emails table does in thunderbird.

  2. #2
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: QSplitter and QTableWidget

    Add a layout to the QSplitter and then add your 2 tablewidgets to it.
    like,

    Qt Code:
    1. QHBoxLayout* pHNewLayout = new QHBoxLayout(splitter);
    2. pHNewLayout ->addWidget(tablewidget1);
    3. pHNewLayout ->addWidget(tablewidget2);
    4. splitter->setLayout(pHNewLayout );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSplitter and QTableWidget

    Quote Originally Posted by nikhilqt View Post
    Add a layout to the QSplitter and then add your 2 tablewidgets to it.
    This still doesn't make my two tables to expand to their maximum available space and stay stretched...

  4. #4
    Join Date
    Sep 2009
    Location
    Finland
    Posts
    63
    Thanks
    1
    Thanked 22 Times in 19 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QSplitter and QTableWidget

    http://doc.qt.nokia.com/4.6/qtableview.html

    By default, the cells in a table do not expand to fill the available space.

    You can make the cells fill the available space by stretching the last header section. Access the relevant header using horizontalHeader() or verticalHeader() and set the header's stretchLastSection property.

    To distribute the available space according to the space requirement of each column or row, call the view's resizeColumnsToContents() or resizeRowsToContents() functions.

  5. #5
    Join Date
    Jan 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSplitter and QTableWidget

    tsp, thanks, that's exactly what I was looking for.
    it's not a matter of not reading the documentation, it's just that I've been looking at this from the wrong angle... I thought it's a matter of layouting...
    Thanks a million, this solves my problem.

Similar Threads

  1. Bug in QSplitter with Qt4.5.1
    By araglin in forum Qt Programming
    Replies: 1
    Last Post: 28th April 2009, 07:45
  2. QSplitter
    By weixj2003ld in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2009, 13:46
  3. New to QSplitter
    By bruccutler in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2007, 16:43
  4. QSplitter and QStackedWidget
    By nikita in forum Qt Programming
    Replies: 4
    Last Post: 15th November 2006, 04:52
  5. QSplitter
    By Solarity in forum Newbie
    Replies: 2
    Last Post: 10th February 2006, 17:05

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.