PDA

View Full Version : checkboxes in a tableview,



mimmo_kallon
13th March 2008, 16:47
hi, I have a problem with a Table View. It has got 2 columns, the first with checkboxes, the second have Strings coming out from a DB query.

I need to save a file containing only the cells in the second coloumn with checked checkboxes(in the 1st one).

I fill the first column with this portion of code:



for (row=0; row<model->rowCount(); row++){
QString name="check_"+QString::number(row+1);
ch = new QCheckBox(name);
ch->setObjectName(name);
ch->setChecked(Qt::Checked);
view->setIndexWidget(model->index(row,0),ch);}


after filling the first column in this way I can't access the state of the checkboxes to select the rows that I want to save in the file.

I am unable to get the state of the checkboxes maybe for the wrong way i used to set the object name.

have you got any idea to help me? thanks in advance!

wysota
13th March 2008, 17:17
Hmm... definitely not the right way to do it. Take a look at Qt::CheckStateRole and Qt::ItemIsUserCheckable and forget about index widgets.

mimmo_kallon
13th March 2008, 18:54
sorry but can you be more practical? i'm very new to qt programming (1 month) and i have greats difficulties to find useful examples for really beginners like me.

Qt::CheckStateRole and Qt::ItemIsUserCheckable are to set the properties of the checkboxes i suppose, but now they works like i want with my code, there are some reason because i shouldn't use it? is it deprecated ?

if I have to forget about index widgets how can i do what i need? i tried to use QItemDelegate with no success, and also it's too much complicated for my little job. (create a custom viewtable with checkbox on first coloumn and textview on the second coloumn)

have you a simple example where i can look how to make something that can help me capturing only the text i need to take? :crying:

thanks for helping me.

jpn
13th March 2008, 19:01
Hopefully this thread helps: QSqlTableModel and checkboxes with SQLite database (http://www.qtcentre.org/forum/f-newbie-4/t-qsqltablemodel-and-checkboxes-with-sqlite-database-12008.html)