|
|
I think you need to answer the following question.
Is your relationship between the qwidget a ISA or a HASA....
Without that question being answered, you really wont know where to
begin.
Ie Is the new qwidget a label? Or a does it have a label.
If it is a label, and the only difference is how the frame around it is
painted... Why not just derive from QLabel and override the necessary
paint methods for qframe/qlabel. Since qlabel ISA qframe it shouldn't
be that hard.
Scott
-----Original Message-----
From: Andrew Medico [mailto:medico@xxxxxxxxxx]
Sent: Friday, June 16, 2006 10:08 AM
To: qt-interest@xxxxxxxxxxxxx
Subject: Re: Widget Subclassing
Andreas Pakulat wrote:
> On 16.06.06 11:58:29, Andrew Medico wrote:
>> How would I go about subclassing a widget (say a QLabel) so that the
base class
>> widget is a child of the subclass? (I want to draw the base class
widget inside
>> a QFrame)
>
> Huh?
>
>> I know I could do this by making a custom QWidget and making a QLabel
a member
>> object, but then I'd have to do a ton of overhead to wrap all the
QLabel's
>> signals and slots.
>
> Aah.
>
>> Any thoughts? I hope it's possible and I'm just missing something
basic.
>
> I think you're taking the wrong approach. Could you explain a bit more
> what you're trying to accomplish? Just painting a QLabel onto a QFrame
> can be done without any subclassing, by just making the label a child
> object of the frame.
My ultimate goal is to end up with an object that can be used as a
QLabel (it has all the same signals and slots), but to have the label
inside a QFrame.
I know I could do something like this, but I'm hoping to avoid
reimplementing every single slot and member function. Even if I do that,
the object still couldn't be passed to functions that expect a QLabel*
argument.
class MyFramedLabel: public QWidget {
public:
MyFramedLabel(QWidget* parent = NULL);
~MyFramedLabel();
public slots:
void setText(const QString& text);
void clear()
private:
QLabel* _label;
}
MyFramedLabel::MyFramedLabel(QWidget* parent):
QWidget(parent)
{
QFrame* frame = new QFrame(this);
frame->setLineWidth(2);
frame->setFrameStyle(QFrame::Box || QFrame::Raised);
_label = new QLabel(frame);
}
MyFramedLabel::~MyFramedLabel()
{
delete _label;
}
MyFramedLabel::setText(const QString& text) {
_label->setText(text);
}
void MyFramedLabel::clear()
{
_label->clear();
}
--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/
--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/
|
|