Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is it possible to put a QGroupBox into a cell of QTableWidget ??
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 5.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • jiapei100J Offline
    jiapei100J Offline
    jiapei100
    wrote on last edited by
    #1

    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

    Welcome to Longer Vision
    https://www.longervision.com

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alizadeh91
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mhcrnl
        wrote on last edited by
        #3

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

        Salutare !!!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alizadeh91
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vezprog
            wrote on last edited by
            #5

            @
            // 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.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mhcrnl
              wrote on last edited by
              #6

              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.

              Salutare !!!

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vezprog
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mhcrnl
                  wrote on last edited by
                  #8

                  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()));
                  ...
                  }@@
                  

                  Salutare !!!

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    vezprog
                    wrote on last edited by
                    #9

                    @
                    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.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved