Adding QGroupBox to QTabWidget
Greetings,
I am required to add QGroupBox objects (each containing a QTableWidget) to the QTabWIdget which resides on the central widget of my applications main window.
I have been unable to add the QGroupBox objects to the QTabWidget object. I assume it is because I don't know what to pass into the ui.setupUI( ??? ) function. The group box with the table in it appears in a separate window unattached to the programs main window when using the following code.
Code:
{
ui.setupUi( this );
setCentralWidget( m_pCentralWidget );
// create tabs
ui.tabWidget = m_tabWidget;
m_tabDMX = new DMXTable( this );
ui.tabWidget->addTab( m_tabDMX, tr("First Tab") );
m_tabAll = new AllTab( this );
ui.tabWidget->addTab( m_tabAll, tr("Second Tab") );
// Load frame with required stuff; Place widgets in frame; left to right
qFrame
->setFrameRect
( QRect( 0,
0,
0,
0 ) );
// 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 );
frameLayout
->setSizeConstraint
( QLayout::SetMaximumSize );
frameLayout->addWidget( m_onlineChk, 0, Qt::AlignRight );
frameLayout->insertStretch( 0, 0 );
qFrame->setLayout( frameLayout );
// Put everything onto the main window.
// Tab widget is 1st
m_centralLayout->addWidget( m_tabWidget, 1, 0, 1, 1);
// Frame is on bottom (just above the status bar)
m_centralLayout->addWidget( qFrame, 2, 0, 1, 1 );
m_pCentralWidget->setLayout( m_centralLayout );
m_pExitAct
= new QAction( tr
("E&xit"),
this );
m_pExitAct->setShortcut( tr("Ctrl+Q") );
connect( m_pExitAct, SIGNAL(triggered()), this, SLOT(close()) );
m_pFileMenu = menuBar()->addMenu( tr("&File") );
m_pFileMenu->addAction( m_pExitAct );
show();
}
Code:
// DMX Table Tab Class
{
m_parent = reinterpret_cast<MainWin*>( pParent );
ui.setupUi( m_parent );
// ui.setupUi( this );
m_onlineGroupBox
= new QGroupBox( tr
("Online Devices") );
sLabels << "Status" << "Name" << "Type" << "IP Address" << "Model Name";
m_pOnlineTable->setHorizontalHeaderLabels( sLabels );
m_pOnlineTable->setColumnWidth( 0, 40 );
m_pOnlineTable->setColumnWidth( 1, 150 );
m_pOnlineTable->setColumnWidth( 2, 130 );
m_pOnlineTable->setColumnWidth( 3, 120 );
m_pOnlineTable->setColumnWidth( 4, 200 );
pTableArea->setWidgetResizable( true );
pTableArea->setWidget( m_pOnlineTable );
layout->addWidget( pTableArea, 0, 0 );
m_onlineGroupBox->setLayout( layout );
m_onlineGroupBox->show();
}
If I use "ui.setupUi( this )" in the DMXTable class I get the following compiler error: 'Ui_DMXTableClass::setupUi': cannot convert parameter 1 from 'DMXTable *const' to 'QMainWindow *'.
I don't understand what to pass to the setupUI() function to get the QGroupBox to show on the tab widget. Anyone know what I am doing wrong?
Re: Adding QGroupBox to QTabWidget
You don't have to pass anything there. Just create your tab widget and set it as the central widget. You shouldn't touch setupUi() at all.
Code:
ui.setupUi(this);
setCentralWidget(tw);
tw->addPage(gb1, "first");
DMXTable *t1 = new DMXTable;
l->addWidget(t1);
//...
}
Re: Adding QGroupBox to QTabWidget
wysota, thanks for the reply.
Your solution works fine. I was trying to copy code used in setting up tabs in a dialog and was not being careful about what I culled.
This is, by far, the most helpful forum I've ever seen. You folks are great!