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



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

    @ QGroupBox *groupBox = new QGroupBox(tr("Exclusive Radio Buttons"));

     QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1"));
     QRadioButton *radio2 = new QRadioButton(tr("R&adio button 2"));
     QRadioButton *radio3 = new QRadioButton(tr("Ra&dio button 3"));
    
     radio1->setChecked(true);
     QVBoxLayout *vbox = new QVBoxLayout;
     vbox->addWidget(radio1);
     vbox->addWidget(radio2);
     vbox->addWidget(radio3);
     vbox->addStretch(1);
     groupBox->setLayout(vbox);@
    

    Since groupBox is a QWidget, I would like add groupBox into a widget cell as :
    @ui->tableWidget->setCellWidget(0, 4, groupBox);@

    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



  • The way that i know!:
    you have to write a delegate to do this (from QStyledItemDelegate). That's so easy and straightforward. Go to this: http://doc.qt.digia.com/stable/model-view-programming.html#delegate-classes



  • Hello QtToppers!
    I have a question:
    How can i insert a lineEdit data into QTableWidget?



  • I can't understand your question? what do you mean by insert a lineEdit data into QTableWidget?!!!



  • @
    // list for combo
    QStringList list;
    list << "";
    list << "Something";

    // create the combo
    listCombo = new QComboBox(this);
    listCombo->addItems(list);

    // map to table widget item
    ui->tableWidget->setCellWidget(11, 1, listCombo);
    @

    This indeed has always worked for me with combo boxes, one would assume the group box functionality would remain the same. Make sure you set your table widget to auto resize.



  • bq. bq. Hello QtToppers!
    I have a question:
    How can i insert a lineEdit data into QTableWidget?

    I want to be able to insert the data in some text boxes/spin boxes and then on button click the data should be added in the table.



  • The task you are asking of is very simple to implement. Look up the basics on signals and slots.

    1. Allow user to input data into text boxes / spin boxes
    2. Pick up the event from the button (connected to a slot)
    3. Gather the data the user has input into the text boxes / spin boxes
    4. Create a QTableWidgetItem(s) and add the contents from the user input
    5. Insert the QTableWidgetItem into the row/column where you would like it in the QTableWidget

    For signals and slots:
    http://qt-project.org/doc/qt-4.8/signalsandslots.html

    For QTableWidgetItem:
    http://qt-project.org/doc/qt-4.8/qtablewidgetitem.html

    For QTableWidget (look at setItem() under public functions):
    http://qt-project.org/doc/qt-4.8/qtablewidget.html



  • I thing this is:
    @@ Dialog::Dialog(QTableWidget *table, QWidget *parent)
    : Dialog(parent), m_table(table)
    {
    ....
    }

    void Dialog::saveDataIntoTable()
    {
    if (!m_table)
    return;
     
    const int currentRow = m_table->rowCount();
    m_table->setRowCount(currentRow + 1);
     
    m_table->setItem(currentRow, 0, new QTableWidgetItem(m_lineEdit1->text()));
    m_table->setItem(currentRow, 1, new QTableWidgetItem(m_lineEdit2->text()));
    ...
    }@@


  • @
    Dialog::Dialog(QTableWidget *table, QWidget *parent) : Dialog(parent), m_table(table)
    {
    }

    void Dialog::saveDataIntoTable()
    {
    if (!m_table)
    return;

     const int currentRow = m_table->rowCount(); 
     m_table->setRowCount(currentRow + 1); 
     m_table->setItem(currentRow, 0, new QTableWidgetItem(m_lineEdit1->text())); 
     m_table->setItem(currentRow, 1, new QTableWidgetItem(m_lineEdit2->text()));
    

    }
    @

    I don't know your application but that would be a way to do it. You might want to put your code in between the tag symbols for future reference.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.