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. Add table in groupbox
Forum Update on Monday, May 27th 2025

Add table in groupbox

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.6k Views
  • 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.
  • S Offline
    S Offline
    sidharth
    wrote on 3 Jun 2013, 10:58 last edited by
    #1

    i am new to qt.please can anybody tell me how can i add a table inside a groupbox from designer.i want i want to add one row and four columns in a table.i want to access each data in the column and row .so please tell me how to drawit..and if possible send me the code.
    thankyou

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on 3 Jun 2013, 11:56 last edited by
      #2

      [quote author="sidharth" date="1370257133"]i am new to qt.please can anybody tell me how can i add a table inside a groupbox from designer.i want i want to add one row and four columns in a table.i want to access each data in the column and row .so please tell me how to drawit..and if possible send me the code.
      thankyou[/quote]

      You can easily drag and drop the components to your MainWindow in designer why not give it a try first. Since you are new to Qt I would suggest you to go through few "tutorials":http://www.voidrealms.com/tutorials.aspx?filter=qt.

      For dealing with table you can either use a QTableWidget or QTableView. First give it a try and incase you face any issues feel free to ask.

      Best Regards,

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sidharth
        wrote on 3 Jun 2013, 12:32 last edited by
        #3

        thanx for motivating me.i tried it and my table is drawn .but how can i add items and contents in the table. i have four columns and one row .now please tell me how to add the contents in the rows and columns...
        thankyou

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on 3 Jun 2013, 12:42 last edited by
          #4

          Good I assume that you are using a QTableWidget , If you want to add the contents through designer then double-click on the table and look for Items tab n start adding.

          If you want to add through code then you need to use QTableWidgetItem.

          eg :-

          @ for (int r=0; r<1; r++)
          {
          for (int c=0; c<4; c++)
          {
          QTableWidgetItem *item = new QTableWidgetItem();
          item->setText(QString("Row %1 Col %2").arg(r).arg(c));
          ui->tableWidget->setItem(r,c,item);
          }
          }@

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jeroentjehome
            wrote on 3 Jun 2013, 12:51 last edited by
            #5

            Hi,
            Just a quick more explanation about the code of Sam (not that it isn't clear!). The QTableWidgetItem is a class designed to hold text/icons etc for a single cell. When the item is given to the tableWidget (setItem()) the parent of the item will also be the tableWidget. So need to consider deletion of the item if the table is removed. When the parent is deleted, all children no longer referenced are deleted automatically.
            The QTableWidget cell can also be a QLabel, QComboBox or anything you like that is a derived QWidget.
            The big disadvantage of the QTableWidget is that you need to manually "update" every cell whereas the model/view tables are more dynamically updated from changing data. (but that might be a bit to advantaged for now)
            Greetz

            Greetz, Jeroen

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sidharth
              wrote on 5 Jun 2013, 07:27 last edited by
              #6

              thankyou sir.
              your code really helped me alot.i actually want that after every 1 second my items in the table changes..
              suppose i have c=a+b in a for loop and i want after every i second my table gets updated for very new value of c using Qtimer.please help me with a code lyk u sent me earlier.and take xample of c=a+b.

              thankyou.

              1 Reply Last reply
              0

              1/6

              3 Jun 2013, 10:58

              • Login

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