PDA

View Full Version : QTabWidget Placement and Display



mclark
16th January 2007, 20:13
Greetings,

I have a program that currently stacks 2 QGroupBox objects and a QFrame object vertically on the central widget of the QMainWindow. A last minute UI change requires me to place the QGroupBox objects on a QTabWidget.

Here I'm running into tab widget problems:

1) I have been unable to position the QTabWidget on the main windows central widget without having it overwrite part of the main menu area. How can I position the tab widget so the main menu will be fully shown?

2) The QTabWidget appears to overwrite the QFrame in main window. It actually seems to extend well beyond the window both vertically and horizontally. Previously, with just the QGroupBox objects (no tab widget) I could use the following code to show both group boxes and frame:

QFrame* qFrame = new QFrame( this );
qFrame->setFrameRect( QRect( 0, 0, 0, 0 ) );
qFrame->setFrameStyle( QFrame::Box | QFrame::Plain );

// Checkbox in frame
m_onlineChk = new QCheckBox( "Show Online Table ", qFrame );
m_onlineChk->setToolTip( "Show/Hide Online Table" );
connect( m_onlineChk, SIGNAL( clicked() ), this, SLOT( onlineClicked() ) );
m_onlineChk->setCheckState( Qt::Checked );

QHBoxLayout* frameLayout = new QHBoxLayout( qFrame );
frameLayout->setSizeConstraint( QLayout::SetMaximumSize );
frameLayout->addWidget( m_onlineChk, 0, Qt::AlignRight );
frameLayout->insertStretch( 0, 0 );
qFrame->setLayout( frameLayout );

m_centralLayout = new QGridLayout;

// Configuration Table is 1st
m_centralLayout->addWidget( m_cfgGroupBox, 1, 0, 1, 2 );
m_centralLayout->setRowMinimumHeight( 1, 300 );

// Online Table is in middle
m_centralLayout->addWidget(m_olnGroupBox, 2, 0, 1, 2);
m_centralLayout->setRowMinimumHeight( 2, 300 );

// Frame is on bottom (just above the status bar)
m_centralLayout->addWidget( qFrame, 3, 0, 1, 2 );
m_centralLayout->setRowMinimumHeight( 3, 30 );

I'm using this code to try and display the tab widget on top and the frame on the bottom of the main windows central widget:

m_centralLayout = new QGridLayout;

// Tab widget is 1st
m_centralLayout->addWidget( m_tabWidget, 1, 0, 1, 1);
m_centralLayout->setRowMinimumHeight( 1, 300 );

// Frame is on bottom (just above the status bar)
m_centralLayout->addWidget( qFrame, 2, 0, 1, 1 );
m_centralLayout->setRowMinimumHeight( 2, 30 );

m_pCentralWidget->setLayout( m_centralLayout );

How can I add both the tab widget and frame to the central widget?

mclark
16th January 2007, 21:34
Solved!

If I delay setting the central widget until after creating the tab widget, frame and layout, it doesn't overwrite the main menu. Weird...