How To Make a QTreeView Object Resize to Match the Main Window?

43 Views Asked by At

I am using a QTreeView to display information and I want this to take up the entire client area of the main window (less the area of its menu, toolbar, and status bar). When the main window is resized, the QTreeView should be resized.

My MainWindow class (derrived from QMainWindow) implements resizeEvent() as this:

void MainWindow::resizeEvent( QResizeEvent * event )
{
    List->resize( event->size().width(), event->size().height() - statusBar()->size().height() );
    QMainWindow::resizeEvent( event );
}

List is a QTreeView pointer initialized in the constructor of the MainWindow class:

    List = ui->centralwidget->findChild<QTreeView*>( "ElementView" );

I don't see any resizing of the QTreeView. I have tried this without the adjustment for the height of the status bar as well.

I have also tried calling resize() for the centralwidget instead of the QTreeView, as well as calling it for both the QTreeView and the centralwidget, but pretty much nothing changes. I say "pretty much" because the one thing that changes is that the vertical scroll bar that initially appears for the QTreeView (because there is more than a screen full of information) will disappear when the main window is resized, even though it is still needed.

0

There are 0 best solutions below