PDA

View Full Version : Spreadsheet of QCheckBoxes...help!



JonathanForQT4
27th June 2007, 09:55
Hello all,

I have just been told to program a spreadsheet looking area of checkboxes, each cell in the spread sheet being a checkbox.

The axis of the spreadsheet (rows) is the a unique object and the other axis (columns) are properties that can be turned on for each object. When a user clicks on a object name, all the properties for the object should be selected or unselected. If the user clicks on a property name then all the check boxes for each object should have that property selected or unselected....

Any ideas of how I should approach the problem?

Cheers,

Jonathan

jacek
27th June 2007, 14:01
Maybe you could use QTableView/QTreeView and a custom model with checkable items?

JonathanForQT4
29th June 2007, 14:42
from what I can see so far....you can set cells selected, but you can't set the cell to be a widget....they need to be of type QTableWidgetItem or did I miss something?

how would you implement this "custom model"?

thanks

Jonathan

marcel
29th June 2007, 18:31
What about QTableWidget::setCellWidget( int row, int col, QWidget* widget )?

Regards

jacek
29th June 2007, 22:20
how would you implement this "custom model"?
You will have to subclass QAbstractTableModel and implement few methods. Everything is described here:
http://doc.trolltech.com/4.3/qabstracttablemodel#subclassing
http://doc.trolltech.com/4.3/model-view-model-subclassing.html
A checkbox will appear if Qt::ItemIsUserCheckable flag is set for the given cell.

JonathanForQT4
6th July 2007, 16:00
jacek: I am very lost with this implementation....I would have to define row and column count to return the number of rows and columns?

since I didn't understand jacek's implementation I have gone ahead with marcel's.....the only thing I can quite get is, when I select a header, which selects all the column (or row)....which signal do I connect to one of my slots which goes through and selects all the qcheckboxes? I can't seem to find a signal that works for mass selection of the cells...only for single selection of the cell through double or single clicking.


cheers,

Jonathan

jacek
6th July 2007, 16:35
I would have to define row and column count to return the number of rows and columns?
Yes.


which signal do I connect to one of my slots which goes through and selects all the qcheckboxes?
Check QItemSelectionModel and QHeaderView classes. You can get pointers to their instances through QTableView methods.

JonathanForQT4
11th July 2007, 10:20
thanks guys, got everything working nicely :D