Results 1 to 3 of 3

Thread: Adding a widget to a QTabWidget

  1. #1
    Join Date
    Mar 2011
    Posts
    82
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Adding a widget to a QTabWidget

    I have a QTabWidget and I want to show different widgets according to the selected tab.

    I thought doing a m_tabwidget->addTab(pWidgetIWantToShow, "Title") was the way to go,but albeit the tab with the "Title" title is being created, nothing is being displayed.

    As it is only one tab so far, itshould set itself to default automatically (as I understood it, at least).

    Am I doing something wrong? Missing something maybe?
    Qt Code:
    1. m_pTopLayout = new QVBoxLayout(this);
    2.  
    3. m_pTabWidget = new QTabWidget(this);
    4. m_pTopLayout->addWidget(m_pTabWidget);
    5.  
    6. m_pRightCB = new QSSRoundedCombo(this);
    7. m_pLeftCB = new QSSRoundedCombo(this);
    8. m_pComboLayout = new QHBoxLayout(this);
    9. m_pComboLayout->addWidget(m_pLeftCB);
    10. m_pComboLayout->addWidget(m_pRightCB);
    11. m_pTopLayout->addLayout(m_pComboLayout);
    12.  
    13. m_pHistogramWidget = new HistogramWidget();
    14. m_pTabWidget->addTab(pHistogramWidget , "Histogram");
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Adding a widget to a QTabWidget

    Where is your code that puts anything on the HistogramWidget? If there is nothing on this widget then you will see nothing in the tab widget.

    You can call QTabWidget::setCurrentWidget() or QTabWidget::setCurrentIndex() (with the index returned by addTab()) to ensure the newly added widget is displayed.

  3. #3
    Join Date
    Dec 2010
    Posts
    20
    Thanks
    9
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adding a widget to a QTabWidget

    Quote Originally Posted by alitoh View Post
    I have a QTabWidget and I want to show different widgets according to the selected tab.

    I thought doing a m_tabwidget->addTab(pWidgetIWantToShow, "Title") was the way to go,but albeit the tab with the "Title" title is being created, nothing is being displayed.

    As it is only one tab so far, itshould set itself to default automatically (as I understood it, at least).

    Am I doing something wrong? Missing something maybe?
    Qt Code:
    1. m_pTopLayout = new QVBoxLayout(this);
    2.  
    3. m_pTabWidget = new QTabWidget(this);
    4. m_pTopLayout->addWidget(m_pTabWidget);
    5.  
    6. m_pRightCB = new QSSRoundedCombo(this);
    7. m_pLeftCB = new QSSRoundedCombo(this);
    8. m_pComboLayout = new QHBoxLayout(this);
    9. m_pComboLayout->addWidget(m_pLeftCB);
    10. m_pComboLayout->addWidget(m_pRightCB);
    11. m_pTopLayout->addLayout(m_pComboLayout);
    12.  
    13. m_pHistogramWidget = new HistogramWidget();
    14. m_pTabWidget->addTab(pHistogramWidget , "Histogram");
    To copy to clipboard, switch view to plain text mode 
    have u try this?

    Qt Code:
    1. m_pTabWidget->setCurrentWidget(pHistogramWidget);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 6
    Last Post: 21st August 2013, 12:53
  2. Qt Designer Solved: Adding widgets to QTabWidget layout
    By koan in forum Qt Tools
    Replies: 1
    Last Post: 13th February 2011, 23:35
  3. Adding tabs in a QTabWidget
    By Hogwarts in forum Qt Programming
    Replies: 3
    Last Post: 8th February 2011, 19:40
  4. [QTabWidget] Adding additional button
    By winuser in forum Newbie
    Replies: 1
    Last Post: 3rd December 2010, 12:56
  5. Adding QGroupBox to QTabWidget
    By mclark in forum Newbie
    Replies: 2
    Last Post: 17th January 2007, 16:27

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.