[PyKDE] [PyQt3] alignment issue on subclassed QTableItem

Jim Bublitz jbublitz at nwinternet.com
Fri Sep 8 02:16:46 BST 2006


On Thursday 07 September 2006 14:24, Hans-Peter Jansen wrote:
> Hi Jim,
>
> Am Donnerstag, 31. August 2006 23:42 schrieb Jim Bublitz:
> > Sorry - can't help with QCheckBox/QButton. I implemented checkboxes
> > with pixmaps, I think because I didn't like the way the Qt checkboxes
> > looked and worked.
> >
> > It's fairly simple - I kept the underlying data in a list of one
> > tuple per row. So when loading the table from the list, I just had to
> > select which pixmap to assign to the cell, and then grab the table's
> > 'clicked' signal to respond to mouse clicks for columns with
> > checkboxes, and then toggle the pixmap assigned.
>
> Nice idea, but does your approach allows to center the bitmap? IIRC the
> QTableItem code, bitmaps always appear left to some text, but I don't
> know, if the alignment() method trick can be applied here.

I really don't know. I don't do anything to align the pixmaps. The checkbox 
pixmap is smaller than the cell and sits at the lower left, which works fine 
because I draw the "check"  with "checkmark" (sort of like the left side side 
of a square root radical sign, or like the Borland-style graphics used on 
their "OK" buttons) that extends to the upper right.

The other pixmap I use in a different column is a large arrow pointing either 
left or right. I don't recall if I customized the pixmap to allow for 
alignment or not. Either way, the problem didn't come up, so I haven't played 
with alignment.

Neither case has any text associated, so maybe I sized the pixmaps to fill the 
cell. 


> When I was on holidays last week, I found some time to look more deeply
> into this issue without feeling too bad about wasting time in miniature
> issues. I subclassed a QWidget for the checkbox editor, where I added
> mouse and keyboard handlers.
>
> Now it behaves reasonably well, with only a sub minor issue left on
> focus handling. Qt3 tables know about two different focus styles:
> FollowStyle and SpreadSheet. The former paints the usual wireframe
> around the cell, while the latter draws a black rectangle. The problem
> is, it paints them on top of the table grid, and I couldn't manage it
> to get drawn there correctly for my CheckTableItems.
>
> I also tried to use the QTable.paintFocus(), but couldn't get the
> geometry right. Doing it myself, it's getting hairy: based on the
> viewport geometry, one has to calculate the grid coordinates taking
> (missing) headers into account.. Needless to say, one has to subclass
> QTable, too. Oh well.

I did a widget with a small circular button that pops up a list or calendar 
and an associated edit box. It was easier to do all of the geometry in the 
widget and stick the widget in the cell. I use it every day and I'm still not 
happy with the way focus and tabbing work.  I found that kind of confusing.

> My current approach limits the focus painting into the cell, but the
> test code reveals an off by one paint deviation depending on which cell
> had the focus before: run the test code, move the cursor back and forth
> (by keyboard) in both top cells, and then inside the checkbox column.
> In the former case, the bottom and right part of the focus frame is
> missing for the checkbox column, while in the latter case, it is drawn
> as expected inside the cell. Funny, isn't it..

I recall some similar problems, but it's been a while since I dealt with them 
and don't really remember the details.

> Still not completely satisfied :-[

I've always thought table widgets in Linux suck - it's the one (and only) 
thing I miss about Windows. Borland's tables were quite nice to use, but even 
they had problems. I originally hacked GTK's table widget into something I 
liked fairly well, but the app that used it I quit using years ago. They're 
surprisingly difficult to do well and usably.

Jim




More information about the PyQt mailing list