PDA

View Full Version : QTableView add row



Seth90
19th July 2011, 15:47
QTableView add row
Hi guys,
i tried in various way to add row in QTableView without using QSqlQueryModel.
I'd like to create a table then for each row is describes in 3 colums:



__________________________________________________ ____
_________
| | Nane: ..... _________
| IMAGE | Description: ........ | button |
| | |____ok___|
|________|

__________________________________________________ ____



for image i use a QLabel, and i'd like to use the same thing for Name and Description, But I don't know how create a model for rows, and insert data..
Someone can help me?

Thanks.

Santosh Reddy
19th July 2011, 15:55
If you arer not sure how to implement model, then you can QTableWidget, it be simple to use, and still does what you want.

Seth90
19th July 2011, 16:17
thank you,
i try to use QTableWidget, but however i don't understand how to add items in row...
i try:



ui->tableWidgetAll->insertRow(1);
ui->tableWidgetAll->insertColumn(1);
QTableWidgetItem *i= new QTableWidgetItem ( "test");

ui->tableWidgetAll->setItem(0,0, i);


but there isn't no change in table :(

Santosh Reddy
19th July 2011, 16:27
you need to add new row, and then setItem()

ui->tableWidgetAll->insertRow(0);

also note that row and column index start from 0 (not from 1)

Seth90
19th July 2011, 16:32
ok, thank you again :) i've understand than the int describes the numbers of row to add.

How i add new item?
like this?



ui->tableWidgetAll->setItem(0,0,QTableWidgetItem(??));

Santosh Reddy
19th July 2011, 16:42
ui->tableWidgetAll->setItem(0,0, new QTableWidgetItem("Item Text")); //this will set the item on row 0 column 0

Seth90
19th July 2011, 16:42
like this

ui->tableWidgetAll->insertRow(0);

QTableWidgetItem* item = new QTableWidgetItem;
item->setText("test");
ui->tableWidgetAll->setItem(0, 0, item);

add new row, but no text is shown :(

Santosh Reddy
19th July 2011, 16:45
Did you read QTableWidgetItem Documnetation, I suggest to have look at it.

Seth90
19th July 2011, 17:32
Thank you for your help! :)
I read the documentation... but in the documentation there isn't any example.....
In some way i've done what i need.



ui->tableWidgetAll->setRowHeight(0,100);
ui->tableWidgetAll->insertColumn(0);
ui->tableWidgetAll->insertColumn(1);
ui->tableWidgetAll->insertColumn(2);
ui->tableWidgetAll->insertRow(0);


QTableWidgetItem* item1 = new QTableWidgetItem;
item1->setIcon(QIcon(":/immagine1.jpg"));
ui->tableWidgetAll->setItem(0, 0, item1);

QTableWidgetItem* item2 = new QTableWidgetItem;
item2->setText("test");
ui->tableWidgetAll->setItem(0, 1, item2);

QTableWidgetItem* item3 = new QTableWidgetItem;
item3->;
ui->tableWidgetAll->setItem(0, 3, item3);


The last 2 questions,
1)how to create a QButton in item3?
2)how to do function if i click in item2 or item1? [like a button]

thank you again :), and excuse me for all my questions :(

Santosh Reddy
19th July 2011, 17:40
QPushButton * button = new QPushButton("Push Me to Emit Signal");

connect(button, SIGNAL(clicked()), this, SLOT(MySlot()));

ui->tableWidgetAll->setCellWidget(0, 2, button); // this will set the QPushButton on row 0, column 2, i.e 1st Row and 3rd Column in table

veeresh_QT1234
16th March 2017, 07:20
Hi All,
I want to develop this type of grid view like after clicking edit button for each row of table please refer this link
"http://www.c-sharpcorner.com/uploadfile/1e050f/edit-and-update-record-in-gridview-in-asp-net/" .....guide me for implementing same grid view using Qt and MS Sql server.....

veeresh_QT1234
16th March 2017, 09:27
Hi All,
I want to develop this type of grid view like after clicking edit button for each row of table please refer this link
"http://www.c-sharpcorner.com/uploadfile/1e050f/edit-and-update-record-in-gridview-in-asp-net/" .....guide me for implementing same grid view using Qt and MS Sql server.....