[PyKDE] Tableitem center text + font size
eric3 at pusspaws.net
Thu Sep 7 21:16:21 BST 2006
On Thursday 07 September 2006 20:46, Jim Bublitz wrote:
> On Thursday 07 September 2006 11:51, Dave S wrote:
> > My project (and learning adventure !) continues ...
> > (1) How do I center text in a TableItem ? I realize that I need to set an
> > alignment flag ie AlignHCenter but am struggling to do so. My QT3 docs
> > say ...
> > The Qt class is a namespace for miscellaneous identifiers that need to be
> > global-like. Normally, you can ignore this class. QObject and a few other
> > classes inherit it, so all the identifiers in the Qt namespace are
> > normally usable without qualification. However, you may occasionally need
> > to say Qt::black instead of just black, particularly in static utility
> > functions (such as many class factories). See also Miscellaneous Classes.
> > I have tried many different ways of getting centralization to work
> > including self.AlignHCenter() which fails with
> > File "./view2.py", line 75, in DispErrorHeader self.AlignHCenter()
> > TypeError: 'AlignmentFlags' object is not callable
> > QGVector::remove: Index -3 out of range
> > I am trying to centralize in the context of ...
> > def DispErrorHeader(self, row):
> > self.tableitem = ModTableItem(self.table1, QTableItem.Never,
> > 'Errors') self.AlignHCenter()
> > self.tableitem.SetColors(Qt.red, Qt.gray)
> > self.table1.setItem(row, 0, self.tableitem)
> > self.tableitem.setSpan(1,2)
> > Any Suggestions
> Add another method to the QTableItem subclass from a few days ago:
> def alignment (self):
> # QTableItem has no setAlignment method yet (as is pointed out in
> # a comment in the Qt C source). This is a way to force numbers to
> # right align. The logic here could be expanded to allow choice of
> # alignments. The methods that draw text in cells call alignment()
> # to get the alignment setting. The alternative to this is to
> # overload the text drawing methods. This is easier.
> return Qt.AlignRight # or whichever Qt.Align* you want
> This overloads QTableItem.alignment () - a fairly non-obvious solution. I
> forget exactly where I found out how to do this, but I don't think it's an
> original idea.
> > (2) How do I enlarge the font of text in a TableItem - and possibly
> > invoke 'bold' ? I have to admit I have been mainly banging my head
> > against the alignment problem but this will be my next hurdle - I would
> > appreciate a pointer :)
> In the 'paint()' method from before, call QPainter.setFont () on the
> QPainter before passign it to QTableItem.paint ().
Jim thanks once again - I would never work this out without advice :)
(PS my app is coming on a treat)
More information about the PyQt