[PyKDE] QTable, selections and moving column headers

Jim Bublitz jbublitz at nwinternet.com
Wed Nov 20 08:54:01 GMT 2002


On 20-Nov-02 greg landrum wrote:
> On Tue, 2002-11-19 at 19:57, Jim Bublitz wrote:
> Yeah, that's a better solution.  The filling code I provided is
> just what came out of pyuic.  I wanted a quick and simple demo.

I figured something like that, but you never know. Besides, I had
an answer for that (if not your other questions) :)
 
> Selection:  
> Even with setSelectionMode(QTable.Single) called, left clicking
> on the column/row headers results in the entire column/row being
> highlighted.  Similarly, clicking to set a cell, then
> shift-clicking elsewhere results in the highlighted region
> expanding.  I have to admit that I am just assuming that
> highlighted = selected.

Highlighted and selected are slightly different - I think I have
this right: Highlighted is a visual property you can see on the
screen, selected means the cell(s) have the property of being
selected, as in having a flag set or being in a list of selected
items. For a single cell, being selected means being highlighted,
but I don't believe that for multiple cells, being highlighted
means all being selected.

Anyway, in your program or the tablestatistics.py program in
examples3/, I can highlight groups of cells regardless of
setSelectionMode. You'd have to read back cell, row, or column
properties to see if they're selected. I also tried setDragEnabled
but couldn't drag anything - the table was editable too, and
reading back all of the properties gave the correct values.

I think the highlighting behavior is normal (?) for QTable,
although I haven't tried it with C++. Looking at my code, I wanted
to be able to highlight a single row (currently selected row -
whatever row the cursor was in) and nothing else, and I ended up
subclassing and overloading QTableItem.paint() to do it. IIRC, it's
been this way over several PyQt versions, and I suspect it's Qt
behavior.

On the column/row moving I don't have an answer.
 
> Column/Row Moving:
> Left clicking on a column/row header and then dragging results in
> the selection being expanded as the mouse cursor drags to new
> columns/rows  (again, I'm defining "selection" to be
> "highlighted region").  No dragging occurs.
 
>> The only other thing I can think of at the moment is to make
>> sure the QTable gets focus (look at focusPolicy, setFocus in the
>> Qt docs). 
 
> I think that focus is being obtained (because I can move the
> selection around, drag stuff out, etc.  Just to be sure, I tried
> adding a call to setFocusPolicy(QWidget.StrongFocus), but that
> didn't change any of the behavior described above. 

That seems right - I got the same thing.

Not very helpful - sorry. You might try Qt support and see if they
have better answers (maybe try a C++ version also if you can).


Jim




More information about the PyQt mailing list