Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 7

Qt-interest Archive, August 2006
MVC, QTableView, CheckBox Widget, and Icon question


Message 1 in thread

My apologies beforehand if this question has been answered elsewhere, but I
certainly haven't been able to find it anywhere in this newsgroup, the C++
GUI Programming book, quite a bit of looking on the 'Net, or pouring
through Trolltech's API.

Here goes:

I am attempting to display a model using a QTableView, where each  element
of the model contains an icon, a string, and a QCheckBox that represents
the status of each element: furthermore, each element is supposed to be
displayed in a row of a table. I have implemented my own delegate
(MyDelegate) such that it allows one to edit  (click on or click off) the
column in which the checkbox appears.

I have the following questions:

1) At the moment, I need to click three times on the check box to set or
clear the model's status value. Furthermore, when I am in the edit mode,
the originally displayed checkbox appears under the one which I am editing.
When I subsequently click on a different row, this effect (that is, the
dual-checkboxes) disappears (and the model is correctly updated).

What I would like is to be able to edit each checkbox without having to
perform so many clicks (I believe what is happening is that I am probably
selecting the appropriate cell and then invoking the editor ...  if this is
the case, how do I ensure that simply clicking the cell will open the
editor from the MyDelegate object: that is, the intended behaviour is that
one click on the displayed checkbox should set (or clear) the status value.
However, if this is not the case, then I don't really know what else to
do).

A lesser concern is being able to center, horizontally, the checkbox in the
cell. I have tried to load the Qwidget from the tableview (using an x value
of the row number and the y value corresponding to the column in  which the
checkbox is supposed to appear), and then setting its layout to
Qt:AlignCenter, but I get a segmentation fault: it seems that having a
QWidget setting its own alignment doesn't work ... or (more likely) I am
using this functionality incorrectly.

2) I would also like to be able to center, horizontally, the icon that is
displayed in its own column.

3) The last question is how to prevent the appearance of the dashed-lines
that indicate a selection, when one clicks on any String item? I believe
that someone else had posted a question similar to this, earlier, but I
didn't see how that discussion was relevant to this question.

I need to continue using the MVC paradigm, because it helps with the rest of
my modelling. Was I correct in deciding to use the QTableView or should I
be displaying the model using QTableWidget. From what I have learned thus
far, QTableView should be able to provide me with the functionality I need.
I am beginning to think that I may need to sublcass the QTableView to
provide some of my behaviour, but I haven't found the API to be all that
clear about what methods need to be overridden.

I am including code that demonstrates the problems that I am having.

The application can be built using the "buildTest" script.

I am using Qt 4.1.3.

Thanks in advance for any and all help.

/K 

Attachment:

Attachment: test.tar.gz
Description: GNU Zip compressed data