Results 1 to 5 of 5

Thread: How to maximize QSplitter in a QWidget

  1. #1
    Join Date
    Dec 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default How to maximize QSplitter in a QWidget

    I've a QSplitter inside a QWidget. Within the QSplitter, I've added a QTreeView and a QListView. Both the view widgets have not been populated yet. The QWidget is set to show maximized.

    My question is how to show the QSplitter to be maximized too? Currently, the QSplitter's height is taking up only a portion of the QWidget's area (about a quarter); it's height is not fully stretched to occupy the QWidget. The QSplitter's width, however, has been fully stretched to fill the QWidget.

    Other than hard coding the fixed height to the QSplitter, is there any other way to achieve this? Since different computers may have different resolution, I don't want to set a hard coded height to the QSplitter.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to maximize QSplitter in a QWidget

    What is the point of using a splitter if you want it "maximized"?
    Its sounds more like you need a QStackedWidget.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    Default Re: How to maximize QSplitter in a QWidget

    Quote Originally Posted by high_flyer View Post
    What is the point of using a splitter if you want it "maximized"?
    Its sounds more like you need a QStackedWidget.
    I am trying to replicate the Windows Explorer view where there's a treeview on the left side of the splitter and a listview on the right. The splitter in the explorer is fully stretched to the bottom of the window so that's my aim.

  4. #4
    Join Date
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to maximize QSplitter in a QWidget

    I'm just guessing, but it sounds to me like you haven't put something in a layout that needs to be. Is the widget that your splitter is governing the central widget of the window or has it been added? Did you add it to a layout?

  5. #5
    Join Date
    Dec 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to maximize QSplitter in a QWidget

    Quote Originally Posted by nroberts View Post
    I'm just guessing, but it sounds to me like you haven't put something in a layout that needs to be. Is the widget that your splitter is governing the central widget of the window or has it been added? Did you add it to a layout?
    My splitter has two widgets. Both should be the central. The splitter is added to a layout.
    My code as below: (Do note that the code exists in the constructor of a class inheriting a QWidget)

    splitter = new QSplitter(Qt::Horizontal);

    treeItem = new QTreeView;
    listItem = new QListView;
    QList<int> sizes;
    sizes.append(200);
    sizes.append(600);

    splitter->addWidget(treeItem);
    splitter->addWidget(listItem);
    splitter->setSizes(sizes);
    splitter->setStretchFactor(0, 1);
    splitter->setStretchFactor(1, 1);

    QVBoxLayout *layoutMain = new QVBoxLayout;
    layoutMain->setContentsMargins(0, 0, 0, 0);
    layoutMain->addWidget(splitter);
    layoutMain->addStretch();
    setLayout(layoutMain);
    showMaximized();

Similar Threads

  1. how to disable the maximize button?
    By zabeehkhan in forum Qt Programming
    Replies: 4
    Last Post: 14th April 2010, 07:26
  2. Replies: 0
    Last Post: 30th March 2010, 14:49
  3. Key sequence maximize program
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 11th November 2009, 21:18
  4. why there is no update on maximize? [QTableWidget]
    By macias in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2007, 15:01
  5. Maximize Window Signal
    By ToddAtWSU in forum Qt Programming
    Replies: 9
    Last Post: 8th May 2006, 20: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.