Add table in groupbox
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.
[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.
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.
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...
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.
@ 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));
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)
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.