Results 1 to 2 of 2

Thread: QToolBox Resizing to contents??

  1. #1
    Join Date
    Jun 2008
    Posts
    1
    Qt products
    Qt4

    Default QToolBox Resizing to contents??

    Hi,

    Operating System: Ubuntu, Qt Version 4.3

    I've got problems resizing a QToolBox to its contents. I created a QToolBox and added to each tab a QWidget, each has a different height (width is the same). At the beginning every tab of the QToolBox adjusts to the size of the Widget and displays it correctly (without scrollbar, space...). One QWidget contains a QTableWidget, which is dynamic, that means I can choose if just one row is displayed or two, your three... (by pressing a QPushbutton) At the beginning there are 8 rows. If pressing the button, a signal is emitted and the method updateSegments() should now adjust the size of the QToolBox Tab to the new size of the QTableWidget. Unfortunately this doesn't happen.
    I wonder if I have the wrong QSizePolicy, etc.. I tried with adjustSize(), resize()... in updateSegments().
    Has anybody a clue how to solve the problem?

    Thank you!!!

    I attach part of the code:
    Qt Code:
    1. initializeControlBox()
    2. {
    3. controlBox = new QGroupBox();
    4. controlBox->setFixedWidth(325);
    5.  
    6. m_pTabControl = new QToolBox(controlBox);
    7.  
    8. m_pArmconfig = new QWidget();
    9. m_pTabControl->addItem(m_pArmconfig, tr("Arm Configuration"));
    10.  
    11. m_pToolLayoutVertical = new QVBoxLayout();
    12. m_pToolLayoutVertical->addWidget(m_pTabControl);
    13. m_pToolLayoutVertical->setAlignment(m_pTabControl, Qt::AlignTop);
    14. controlBox->setLayout(m_pToolLayoutVertical);
    15.  
    16. //Widget Arm Configuration
    17. m_pSegLayout = new QGridLayout();
    18.  
    19. m_pNumberSeg = new QLabel("Number of segments");
    20. m_pSelectSeg = new QSpinBox();
    21. m_pSelectSeg->setMaximum(8);
    22. m_pSelectSeg->setMinimum(3);
    23. m_pSelectSeg->setValue(8);
    24. m_pApplySeg = new QPushButton("Apply Segments");
    25. m_pApplySeg->setFixedWidth(110);
    26.  
    27. m_pSelectSegLayout = new QGridLayout();
    28. m_pSelectSegLayout->addWidget(m_pNumberSeg, 0, 0);
    29. m_pSelectSegLayout->addWidget(m_pSelectSeg, 0, 1);
    30. m_pSelectSegLayout->setVerticalSpacing(5);
    31. m_pSelectSegLayout->addWidget(m_pApplySeg, 1, 1);
    32. m_pSelectSegLayout->setAlignment(m_pApplySeg, Qt::AlignRight);
    33.  
    34. // QTableWidget
    35. m_pSegTable = new QTableWidget();
    36. m_pSegTable->setRowCount(8);
    37. m_pSegTable->setColumnCount(4);
    38.  
    39. vboxConfig = new QVBoxLayout();
    40. vboxConfig->addItem(m_pSelectSegLayout);
    41. vboxConfig->addSpacing(10);
    42. vboxConfig->addWidget(m_pSegTable,0, 0);
    43. m_pArmconfig->setLayout(vboxConfig);
    44. }
    45.  
    46. updateSegments() {
    47. m_numberseg = m_pSelectSeg->value();
    48. if (m_numberseg == 3)
    49. {
    50. //hide table rows
    51. m_pSegTable->setRowHidden(0, false);
    52. m_pSegTable->setRowHidden(1, false);
    53. m_pSegTable->setRowHidden(2, false);
    54.  
    55. for (int i=3; i<8; i++)
    56. {
    57. m_pSegTable->setRowHidden(i, true);
    58. }
    59. }
    60. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QToolBox Resizing to contents??

    QTableWidget is a QAbstractScrollArea. The sizeHint() of QTableWidget doesn't take the contents anyhow into account. In fact, QTableWidget, QTableView or QAbstractItemView doesn't even implement sizeHint(). In other words, item views basically don't ask for any specific size because they're happy with what they get. If it's less than the contents require, scroll bars appear.

    If you want a QTableWidget size to follow its contents, you should subclass QTableWidget and reimplement sizeHint(). QTableView and QHeaderView provide necessary functions to calculate size of the contents. You might also want to search the forums for more details. This subject has been discussed before.
    J-P Nurmi

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.