Results 1 to 3 of 3

Thread: QTabWidget does not respect spacing from layout

  1. #1

    Question QTabWidget does not respect spacing from layout

    I have this test case:

    Qt Code:
    1. // Scroll
    2. QScrollArea *sa = new QScrollArea(ui->centralWidget);
    3. sa->setWidgetResizable( true );
    4.  
    5. // Layout for widgets
    6. QVBoxLayout *vl_2 = new QVBoxLayout();
    7. vl_2->setSpacing(0);
    8.  
    9. // Widget to attach the scroll to and the layout
    10. QWidget *widget = new QWidget()
    11. widget->setLayout(vl_2);
    12. sa->setWidget(widget);
    13.  
    14. // Test widgets
    15. QComboBox *cb_1 = new QComboBox();
    16. QComboBox *cb_2 = new QComboBox();
    17. vl_2->addWidget( cb_1 );
    18. vl_2->addWidget( cb_2 );
    To copy to clipboard, switch view to plain text mode 

    And the widgets have 0 space between them.

    But if I add them to a QTabWdiget, it all breaks as if QTabWidget does not respect the set setSpacing(0);

    Qt Code:
    1. // TabWidget
    2. QTabWidget *run_results = new QTabWidget(ui->centralWidget);
    3. run_results->resize( this->size().width() -20, this->size().height() -80 );
    4. run_results->show();
    5.  
    6. // Scroll
    7. QScrollArea *sa = new QScrollArea(ui->centralWidget);
    8. sa->setWidgetResizable( true );
    9.  
    10. // Layout for widgets
    11. QVBoxLayout *vl_2 = new QVBoxLayout();
    12. vl_2->setSpacing(0);
    13.  
    14. // Widget to attach the scroll to and the layout
    15. QWidget *widget = new QWidget()
    16. widget->setLayout(vl_2);
    17. sa->setWidget(widget);
    18.  
    19. // Add the scroll to as the TabWidget tab.
    20. run_results->addTab(sa, "test");
    21.  
    22. // Test widgets
    23. QComboBox *cb_1 = new QComboBox();
    24. QComboBox *cb_2 = new QComboBox();
    25. vl_2->addWidget( cb_1 );
    26. vl_2->addWidget( cb_2 );
    To copy to clipboard, switch view to plain text mode 

    Anyone know what I need to do to force QTabWidget to not resize and move my widgets so that they take all the space?

    I tried to add Qt::AlignTop to the addWdiget but it did nothing other than place the first widget at the top and the next in the middle of the screen.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTabWidget does not respect spacing from layout

    Your code does not show how the tab widget is added to the central widget's layout and how the scroll area is added to the tab widget's layout.

    The problem could very well be that your actual code is also missing these lines.

    Cheers,
    _

  3. #3

    Default Re: QTabWidget does not respect spacing from layout

    @anda_skoa, thanks for the reply. That is all the code for the example. I understand where I went wrong.

    In the first case I add my scrollarea as a sub-widget to the centralwidget. In the second example I add the scrollarea as the centralwidget which expands it to the whole tabwidget.

    I resolved the second case by first adding a holder QWidget as the tabwidget and then adding the scrollarea as a sub-widget to it.

    How do I close a thread as solved?

Similar Threads

  1. Grid Layout -- and buttons spacing
    By Noob in forum Newbie
    Replies: 4
    Last Post: 6th May 2013, 07:30
  2. Control spacing of a QFrame layout using a Stylesheet
    By gmat4321 in forum Qt Programming
    Replies: 1
    Last Post: 21st October 2012, 19:18
  3. Replies: 1
    Last Post: 10th June 2010, 15:21
  4. Replies: 4
    Last Post: 5th September 2009, 15:24
  5. Problem in layout spacing
    By mails.hemant in forum Qt Tools
    Replies: 15
    Last Post: 24th November 2008, 11:48

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.