Hello,

I am using 4.1.0 and have a tab widget in my main window. I add 2 widgets to the first tab and nothing to the subsequent tabs. The Tab_1 widgets show correctly but when I switch between tabs I expect to see my Tab_1 widgets disappear when Tab_2 is selected. This doesn't happen! The tab 1 widgets always show. This would appear to be a widget parenting problem.

I am using the QTabWidget* as the parent of the group boxes and the QGroupBox* as the parent of my table and layout. Can anyone tell me what I'm doing (or not doing) that is causing the Tab_1 objects to display when Tab_2 is displayed?

Qt Code:
  1. MainWin::MainWin( QWidget* parent, Qt::WFlags flags ) : QMainWindow( parent, flags )
  2. {
  3. ui.setupUi( this );
  4. m_pCentralWidget = new QWidget;
  5.  
  6. // create tabs
  7. m_tabWidget = new QTabWidget( this );
  8. ui.tabWidget = m_tabWidget;
  9.  
  10. m_tabDMX = new DMXTable( m_tabWidget );
  11. ui.tabWidget->addTab( m_tabDMX, tr("Tab_1") );
  12.  
  13. m_tabAll = new AllTable( m_tabWidget );
  14. ui.tabWidget->addTab( m_tabAll, tr("Tab_2") );
  15.  
  16. // Load frame with required stuff; Place widgets in frame; left to right
  17. QFrame* qFrame = new QFrame( this );
  18. qFrame->setFrameRect( QRect( 0, 0, 0, 0 ) );
  19. qFrame->setFrameStyle( QFrame::Box | QFrame::Plain );
  20.  
  21. // Checkbox in frame
  22. m_onlineChk = new QCheckBox( "Show Online Table ", qFrame );
  23. connect( m_onlineChk, SIGNAL( clicked() ), this, SLOT( onlineClicked() ) );
  24. m_onlineChk->setCheckState( Qt::Checked );
  25.  
  26. QHBoxLayout* frameLayout = new QHBoxLayout( qFrame );
  27. frameLayout->setSizeConstraint( QLayout::SetMaximumSize );
  28. frameLayout->addWidget( m_onlineChk, 0, Qt::AlignRight );
  29. frameLayout->insertStretch( 0, 0 );
  30. qFrame->setLayout( frameLayout );
  31.  
  32. // Put everything onto the main window.
  33. m_centralLayout = new QGridLayout;
  34. // Tab widget is 1st
  35. m_centralLayout->addWidget( m_tabWidget, 1, 0, 1, 1);
  36. m_centralLayout->setRowMinimumHeight( 1, 300 );
  37. // Frame is on bottom (just above the status bar)
  38. m_centralLayout->addWidget( qFrame, 2, 0, 1, 1 );
  39. m_centralLayout->setRowMinimumHeight( 2, 30 );
  40.  
  41. setCentralWidget( m_pCentralWidget );
  42. m_pCentralWidget->setLayout( m_centralLayout );
  43.  
  44. m_pExitAct = new QAction( tr("E&xit"), this );
  45. m_pExitAct->setShortcut( tr("Ctrl+Q") );
  46. connect( m_pExitAct, SIGNAL(triggered()), this, SLOT(close()) );
  47.  
  48. m_pFileMenu = menuBar()->addMenu( tr("&File") );
  49. m_pFileMenu->addAction( m_pExitAct );
  50.  
  51. show();
  52.  
  53. } // MainWin
  54.  
  55.  
  56. DMXTable::DMXTable( QWidget* pParent ) : QWidget( pParent )
  57. {
  58. m_parent = pParent;
  59.  
  60. createConfigTable();
  61. createOnlineTable();
  62.  
  63. QVBoxLayout* layout = new QVBoxLayout( pParent );
  64. layout->addSpacing( 25 );
  65. layout->addWidget( m_configGroupBox );
  66. layout->addWidget( m_onlineGroupBox );
  67. }
  68.  
  69. void DMXTable::createConfigTable( void )
  70. {
  71. QStringList sLabels;
  72. sLabels << "Status" << "Name" << "Type" << "IP Address" << "Model Name";
  73.  
  74. // Set up the table area.
  75. m_configGroupBox = new QGroupBox( tr("Configured Devices"), m_parent );
  76. m_pConfigTable = new QTableWidget( 1, 5, m_configGroupBox );
  77.  
  78. m_pConfigTable->setHorizontalHeaderLabels( sLabels );
  79. m_pConfigTable->setColumnWidth( 0, 40 );
  80. m_pConfigTable->setColumnWidth( 1, 150 );
  81. m_pConfigTable->setColumnWidth( 2, 130 );
  82. m_pConfigTable->setColumnWidth( 3, 120 );
  83. m_pConfigTable->setColumnWidth( 4, 150 );
  84.  
  85. QHBoxLayout* layout = new QHBoxLayout( m_configGroupBox );
  86. layout->addWidget( m_pConfigTable );
  87. m_configGroupBox->setLayout( layout );
  88. }
  89.  
  90.  
  91. void DMXTable::createOnlineTable( void )
  92. {
  93. QStringList sLabels;
  94. sLabels << "Status" << "Name" << "Type" << "IP Address" << "Model Name";
  95.  
  96. // Set up the table area.
  97. m_onlineGroupBox = new QGroupBox( tr("Online Devices"), m_parent );
  98. m_pOnlineTable = new QTableWidget( 1, 5, m_onlineGroupBox );
  99.  
  100. m_pOnlineTable->setHorizontalHeaderLabels( sLabels );
  101. m_pOnlineTable->setColumnWidth( 0, 40 );
  102. m_pOnlineTable->setColumnWidth( 1, 150 );
  103. m_pOnlineTable->setColumnWidth( 2, 130 );
  104. m_pOnlineTable->setColumnWidth( 3, 120 );
  105. m_pOnlineTable->setColumnWidth( 4, 150 );
  106.  
  107. QHBoxLayout* layout = new QHBoxLayout( m_onlineGroupBox );
  108. layout->addWidget( m_pOnlineTable );
  109. m_onlineGroupBox->setLayout( layout );
  110. }
To copy to clipboard, switch view to plain text mode