PDA

View Full Version : checkboxes



abrou
1st February 2008, 00:04
Below is some code that puts a check box in the first colum of a TableWidget. They are entered nicely in the column, but I have two questions:


for (int i = 0; i < list.size(); ++i)
{
fileTable->setRowCount(j+1);
QCheckBox *inserter = new QCheckBox();
fileTable->setCellWidget(j,0,inserter);
}

1st, how do I align the check boxes to the centre, the only thing i see is for text.

2nd (and more important), I'm not sure how to acces these now. I want to connect them, so that when one is checked, it sends a signal like:

connect( checkbox , SIGNAL( toggeled(bool) ), this, SLOT( getType() ) );

What do I put for checkbox, above? It was created when another signal was called to populate the table.... I'm not sure if I'm being clear.

jpn
1st February 2008, 09:33
The item view framework supports checkable items out of the box. Take a look at QTableWidgetItem::setFlags(). I highly recommend to avoid flooding the table full of item widgets.

item->setFlags(item->flags() | Qt::ItemIsUserCheckable);

abrou
1st February 2008, 18:52
Thanks for the advice. I actually changed what I was going to do, since only two were going to be selected at a time, I thought maybe drag and drop would be better for the user. It seems to be working, although I'm not sure if I'm doing it the best way. Anyway, thanks!