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

André Somers andre at familiesomers.nl
Sat Mar 20 14:30:05 CET 2010


Hi,

I don't think there is an easy way to do what you want. I would go for your
approach 2, deriving from QWidget or QFrame and putting the (modified)
QTableWidget inside of it. You can do the design in QDesigner if you want.
If you want, just supply a pointer to the embedded QTableWidget. Qt itself
does this too, in QComboBox for instance. 

André

-----Oorspronkelijk bericht-----
Van: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] Namens K. Frank
Verzonden: zaterdag 20 maart 2010 1:47
Aan: Qt-interest
Onderwerp: [Qt-interest] Add "external" graphical elements to a derived
widget?

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
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest





More information about the Qt-interest-old mailing list