Results 1 to 5 of 5

Thread: Is it possible to put a QGroupBox into a cell of QTableWidget ??

  1. #1
    Join Date
    Sep 2009
    Location
    Surrey, BC, Canada
    Posts
    110
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    1
    Thanked 2 Times in 1 Post

    Default Is it possible to put a QGroupBox into a cell of QTableWidget ??

    Hi, all:

    I followed the code on page http://doc.qt.digia.com/4.7-snapshot...-groupbox.html . The code patch is attached:


    Qt Code:
    1. QGroupBox *groupBox = new QGroupBox(tr("Exclusive Radio Buttons"));
    2.  
    3. QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1"));
    4. QRadioButton *radio2 = new QRadioButton(tr("R&adio button 2"));
    5. QRadioButton *radio3 = new QRadioButton(tr("Ra&dio button 3"));
    6.  
    7. radio1->setChecked(true);
    8. QVBoxLayout *vbox = new QVBoxLayout;
    9. vbox->addWidget(radio1);
    10. vbox->addWidget(radio2);
    11. vbox->addWidget(radio3);
    12. vbox->addStretch(1);
    13. groupBox->setLayout(vbox);
    To copy to clipboard, switch view to plain text mode 

    Since groupBox is a QWidget, I would like add groupBox into a widget cell as :
    Qt Code:
    1. ui->tableWidget->setCellWidget(0, 4, groupBox);
    To copy to clipboard, switch view to plain text mode 

    But it seems this doesn't work for me at all. Those radios can't show up at all.

    Can anybody help to let me know if it's possible to put a groupBox into a tableWidget cell? If so, how?


    Thanks
    Pei
    Welcome to Vision Open
    http://www.visionopen.com

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: Is it possible to put a QGroupBox into a cell of QTableWidget ??

    Yes it is possible, just make sure the table has the specified row, and column.

    Qt Code:
    1. ui->tableWidget->setRowCount(1);
    2. ui->tableWidget->setColumnCount(5);
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Sep 2009
    Location
    Surrey, BC, Canada
    Posts
    110
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    1
    Thanked 2 Times in 1 Post

    Default Re: Is it possible to put a QGroupBox into a cell of QTableWidget ??

    Thanks Santosh Reddy.

    This doesn't work for me at all... I'm pretty sure my tableWidget does have 6 columns and 6 rows.
    Please refer to http://qt-project.org/forums/viewthread/24742/#114245, somebody answered my question, but that's not the solution I want.


    Any other suggestions please?


    Thank you
    Pei


    Quote Originally Posted by Santosh Reddy View Post
    Yes it is possible, just make sure the table has the specified row, and column.

    Qt Code:
    1. ui->tableWidget->setRowCount(1);
    2. ui->tableWidget->setColumnCount(5);
    To copy to clipboard, switch view to plain text mode 
    Welcome to Vision Open
    http://www.visionopen.com

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: Is it possible to put a QGroupBox into a cell of QTableWidget ??

    Then I will say that you are missing somthing to mention.
    What does the output look like ?
    Are you sure setCellWidget is being called ?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    Default Re: Is it possible to put a QGroupBox into a cell of QTableWidget ??

    Make sure the cell is large enough to show the widget otherwise you will just get the top left corner of the group box.
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv)
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QTableWidget w(6, 6);
    8. QGroupBox *groupBox = new QGroupBox("Radio Buttons", &w);
    9. QRadioButton *radio1 = new QRadioButton("&Radio button 1", &w);
    10. QRadioButton *radio2 = new QRadioButton("R&adio button 2", &w);
    11. QRadioButton *radio3 = new QRadioButton("Ra&dio button 3", &w);
    12. radio1->setChecked(true);
    13. QVBoxLayout *vbox = new QVBoxLayout(groupBox);
    14. vbox->addWidget(radio1);
    15. vbox->addWidget(radio2);
    16. vbox->addWidget(radio3);
    17. vbox->addStretch(1);
    18. groupBox->setLayout(vbox);
    19.  
    20. w.setCellWidget(0, 0, groupBox);
    21.  
    22. // This:
    23. w.resizeRowToContents(0);
    24. w.resizeColumnToContents(0);
    25. // or this:
    26. // w.verticalHeader() ->resizeSection(0, groupBox->sizeHint().height());
    27. // w.horizontalHeader()->resizeSection(0, groupBox->sizeHint().width());
    28. // might be good places to start
    29.  
    30. w.show();
    31.  
    32. return app.exec();
    33. }
    To copy to clipboard, switch view to plain text mode 

    tt.png

Similar Threads

  1. Replies: 3
    Last Post: 9th November 2012, 19:55
  2. repaint a cell or row in QTableWidget
    By alphaqt in forum Newbie
    Replies: 6
    Last Post: 26th June 2012, 12:21
  3. qtablewidget cell's x() , y()
    By BalaQT in forum Qt Programming
    Replies: 1
    Last Post: 7th December 2010, 13:23
  4. Can QPushButton be put into a QTableWidget cell?
    By ShaChris23 in forum Newbie
    Replies: 4
    Last Post: 1st September 2010, 01:18
  5. Replies: 1
    Last Post: 7th December 2009, 19:56

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
  •  
Qt is a trademark of The Qt Company.