Qt-interest Archive, August 2006
Weird selection in QTableView
Message 1 in thread
Hi,
I created a dialog containing a QTableView with Designer. I set the
SelectionBehavior to SelectRows and the SelectionMode to
SingleSelection. When displaying the dialog, the selection settings seem
to be broken:
* single cells, not rows, are selected when clicking into the table
* selected cells are not highlighted in blue (as they usually are),
there only appears a thin dashed line around it
Any idea what I could be doing wrong?
Thanks,
M
--
[ signature omitted ]
Message 2 in thread
Hi Martin.
Do you mean you can only "select" a unique cell ?
In that case, I would say that the thin dashed lines you observe are not
those of the "selected cells", but those of the "current cell".
I would say that SelectRows and SingleSelection probably conflict.
SingleSelection means you can only select one CELL.
SelectRows means that you can select a row, made of various cells.
Perhpas you may try unsetting SingleSelection, then if it is ok try
QAbstractItemView::ContiguousSelection ?
In case you really need to select a unique row, you may try to reimplement
mousePressEvent(...) with something like :
mousePressEvent(...) {
//unselect all
QTableView::mousePressEvent(...)
}
Hope it helps.
Best-
Nicolas
Martin wrote:
> Hi,
>
> I created a dialog containing a QTableView with Designer. I set the
> SelectionBehavior to SelectRows and the SelectionMode to
> SingleSelection. When displaying the dialog, the selection settings seem
> to be broken:
>
> * single cells, not rows, are selected when clicking into the table
> * selected cells are not highlighted in blue (as they usually are),
> there only appears a thin dashed line around it
>
> Any idea what I could be doing wrong?
>
> Thanks,
> M
--
[ signature omitted ]
Message 3 in thread
Nicolas Castagne schrieb:
> I would say that SelectRows and SingleSelection probably conflict.
Sorry to object, but they don't.
> SingleSelection means you can only select one CELL.
> SelectRows means that you can select a row, made of various cells.
SingleSelection means "at the same time only one instance may be
selected", while the SelectRows determines that this instance is a
complete row. Both settings (SelectionMode and SelectionBehaviour) are
AFAIK completely orthogonal.
The OPs problem sound like his settings (assigned in Designer?) get
screwed at the setup of the dialog.
Martin (another one)
--
[ signature omitted ]
Message 4 in thread
Martin Gebert wrote:
> Nicolas Castagne schrieb:
>> I would say that SelectRows and SingleSelection probably conflict.
>
> Sorry to object, but they don't.
>
>> SingleSelection means you can only select one CELL.
>> SelectRows means that you can select a row, made of various cells.
>
> SingleSelection means "at the same time only one instance may be
> selected", while the SelectRows determines that this instance is a
> complete row. Both settings (SelectionMode and SelectionBehaviour) are
> AFAIK completely orthogonal.
>
> The OPs problem sound like his settings (assigned in Designer?) get
> screwed at the setup of the dialog.
>
> Martin (another one)
>
Thanks both of you for your answers. I tried to manually create the
view, that didn't change a thing. So I put in another model (QDirModel)
instead of my custom one, and lo and behold! it works. So the problem
must be somewhere in my model code... but I still find it weired that
the view's selection is influenced in such a way by the model.
Besides the strange highlighting behaviour in the table I described, the
header view also does strange stuff: when there is only one row in the
table and I click on it, the vertical header is 'selected', i.e. the
column headers are in a pushed-in state.
Any idea what might be wrong with that model?
M
--
[ signature omitted ]
Message 5 in thread
Martin schrieb:
> Besides the strange highlighting behaviour in the table I described, the
> header view also does strange stuff: when there is only one row in the
> table and I click on it, the vertical header is 'selected', i.e. the
> column headers are in a pushed-in state.
Which version of Qt4 do you use? I noticed this, too; it is thought to
indicate "all rows for this column are selected" (as in spreadsheets,
like OO Calc or Excel). However I think I noticed this behaviour had
wondermagically vanished with 4.1.3 or .4...?
BTW, the column headers are in the horizontal header...
> Any idea what might be wrong with that model?
No, my crystal ball is currently under repair ;-) Search your code
(everything that affects model or view) for the use of [sS]electionModel.
HTH, Martin
--
[ signature omitted ]
Message 6 in thread
Martin Gebert wrote:
> Martin schrieb:
>> Besides the strange highlighting behaviour in the table I described, the
>> header view also does strange stuff: when there is only one row in the
>> table and I click on it, the vertical header is 'selected', i.e. the
>> column headers are in a pushed-in state.
>
> Which version of Qt4 do you use? I noticed this, too; it is thought to
> indicate "all rows for this column are selected" (as in spreadsheets,
> like OO Calc or Excel). However I think I noticed this behaviour had
> wondermagically vanished with 4.1.3 or .4...?
> BTW, the column headers are in the horizontal header...
Using Qt 4.1.4. The view is capable of doing what I want because it
works with e.g. a QDirModel.
>> Any idea what might be wrong with that model?
>
> No, my crystal ball is currently under repair ;-) Search your code
> (everything that affects model or view) for the use of [sS]electionModel.
Well, my hope was that someone has seen something like this with their
own model. Still it's a pity that you broke your crystal ball. These
things can come in quite handy sometimes...
M
--
[ signature omitted ]
Message 7 in thread
Martin wrote:
> Martin Gebert wrote:
>> Martin schrieb:
>>> Besides the strange highlighting behaviour in the table I described, the
>>> header view also does strange stuff: when there is only one row in the
>>> table and I click on it, the vertical header is 'selected', i.e. the
>>> column headers are in a pushed-in state.
>> Which version of Qt4 do you use? I noticed this, too; it is thought to
>> indicate "all rows for this column are selected" (as in spreadsheets,
>> like OO Calc or Excel). However I think I noticed this behaviour had
>> wondermagically vanished with 4.1.3 or .4...?
>> BTW, the column headers are in the horizontal header...
>
> Using Qt 4.1.4. The view is capable of doing what I want because it
> works with e.g. a QDirModel.
>
>>> Any idea what might be wrong with that model?
>> No, my crystal ball is currently under repair ;-) Search your code
>> (everything that affects model or view) for the use of [sS]electionModel.
>
> Well, my hope was that someone has seen something like this with their
> own model. Still it's a pity that you broke your crystal ball. These
> things can come in quite handy sometimes...
>
> M
Oooookay, as usual it was a stupid little mistake. The model's #flags
method didn't return ItemIsSelectable... adding this flag makes the row
selection work. Just in case someone has the same problem...
M
--
[ signature omitted ]