PDA

View Full Version : QTableView and problems with align



mamyte03@gmail.com
10th November 2007, 14:04
Hello,

I have QTableView and i fill it with checkbox widget's.


QCheckBox editor = new QCheckBox();
tableView->setIndexWidget (index,editor); //index is QModelIndex();

But widgets are alignment to right side. I want alignment to middle.

How can I set this?

jpn
10th November 2007, 15:15
I highly recommend you to get rid of expensive index widgets and make the items checkable instead. This is done by returning Qt::ItemIsUserCheckable amongst other flags in your model's flags() (http://doc.trolltech.com/4.3/qabstractitemmodel.html#flags) implementation. You can adjust text alignment by returning a suitable value for Qt::TextAlignmentRole in model's data() (http://doc.trolltech.com/4.3/qabstractitemmodel.html#data) implementation.

mamyte03@gmail.com
11th November 2007, 21:47
I did that by adding widget to layout, and for layout set TextAligment flag.. It works..

jpn
12th November 2007, 08:10
Just be aware that Qt's model-view framework has built-in support for checkable items. It is considered as a mistake to abuse QComboBoxes for that. The view has put quite a lot of effort to keeping index widgets in correct places, over corresponding items. I hope you don't have too many items because it will be a resource hog..