Results 1 to 2 of 2

Thread: QTabBar - Stop it from collapsing when no tabs are present

  1. #1
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default QTabBar - Stop it from collapsing when no tabs are present

    I'm using a QTabBar widget. When the QTabBar has no more tabs in it, it collapses its height down to nothing until a new tab is added. How can I disable that?
    I want it to stay at a uniform height regardless of whether there are no tabs in it, or multiple tabs.

    I searched the documentation but can't find any info on it. I also tried to work around it by placing the QTabBar within a QWidget, and programmaticly assigning the QWidget's minimum and maximum heights to the QTabBar's height after it contains a tab and is shown, but it re-sized it too large.

    Any suggestions?

  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: QTabBar - Stop it from collapsing when no tabs are present

    QWidget::SetMinimumHeight() as in line 10:
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. class MainWindow: public QMainWindow {
    5. Q_OBJECT
    6. public:
    7. MainWindow(QWidget *p = 0): QMainWindow(p) {
    8. QWidget *central = new QWidget(this);
    9. QTabBar *tb = new QTabBar(this);
    10. tb->setMinimumHeight(50);
    11. QLabel *label1 = new QLabel("Label 1", this);
    12. QLabel *label2 = new QLabel("Label 2", this);
    13.  
    14. QVBoxLayout *layout = new QVBoxLayout(central);
    15. layout->addWidget(label1);
    16. layout->addWidget(tb);
    17. layout->addWidget(label2);
    18.  
    19. setStyleSheet("QTabBar { background: green; }"
    20. "QLabel { background: red; }");
    21.  
    22. central->setLayout(layout);
    23. setCentralWidget(central);
    24. }
    25. };
    26.  
    27. int main(int argc, char *argv[])
    28. {
    29. QApplication app(argc, argv);
    30.  
    31.  
    32. MainWindow m;
    33. m.show();
    34. return app.exec();
    35. }
    36. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 0
    Last Post: 17th November 2011, 12:51
  2. QTabBar make all tabs out of focus
    By migel in forum Newbie
    Replies: 1
    Last Post: 24th August 2011, 13:38
  3. QTabBar adding tabs button "+"
    By alonso15 in forum Newbie
    Replies: 3
    Last Post: 20th May 2011, 23:46
  4. QTabBar color in space inbetween tabs
    By AwDogsgo2Heaven in forum Newbie
    Replies: 1
    Last Post: 12th March 2010, 09:44
  5. QTreeWidgetItem - widget with layout collapsing
    By enkidu in forum Qt Programming
    Replies: 4
    Last Post: 9th August 2009, 23:50

Tags for this Thread

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.