[Qt-interest] Add "external" graphical elements to a derived widget?

K. Frank kfrank29.c at gmail.com
Sat Mar 20 01:47:20 CET 2010


Hi List -

I would like to derive a widget from QTableWidget, but have the custom
widget contain
some additional graphical elements (check boxes, and labels, and the
like) that appear
above the table proper.  Ideally, I would like to use Qt designer to
lay out the custom
widget.

(I am hoping to avoid a discussion of object-oriented purity -- I do
understand that this
kind of derivation has not been granted the good-housekeeping seal of
approval by the
purists, but I would like to forge ahead, nonetheless.)

Is it possible to do this in the Qt framework?  If it is, would it be
a bad idea (for reasons
other than lack of purity)?  Is there a better way to achieve my goal?

The two motivations for deriving from QTableWidget are:

First, my custom widget is nearly a QTableWidget.  The most economical
way to tweak
the functionality of QTableWidget is to derive from it.

Second, I would like to use Qt designer to drop a QTableWidget onto a
ui, and then promote
it to my custom widget.

I have done two things, each of which gives me part of what I want,
but I don't see a way to
do them at the same time.

1)  I have derived a custom widget from QTableWidget.  In my derived
widget I change the
behavior of some of the cells, and add some signals, but I haven't
added any graphical
elements external to the QTableWidget, that is, not embedded in cells
of the table.
In Qt designer I have used QTableWidget in laying out a form, and then
promoted it.

2)  I have derived a custom widget from QWidget, adding to it a child
QTableWidget, as
well as some check boxes and labels external to the QTableWidget, also
as children.
(I used Qt designer to lay out this custom widget.  I also have
promoted QWidget to
this custom widget in Qt designer.)

What I don't see how to do is derive a custom widget from QTableWidget
(rather than
QWidget) and then add the labels and check boxes.  Is there a way to
do this in the
Qt scheme of things?

Thanks.


K. Frank



More information about the Qt-interest-old mailing list