[Qt-interest] Display a widget inside its parent widget

Zhongmiao Li mars.leezm at gmail.com
Sun Dec 12 16:45:10 CET 2010


Hellp Everyone,

could you read my code?  This can be one of the simplest program written in
Qt:

int main(int argc, char *argv[])

{

    QApplication a(argc, argv);

     QWidget* widget=new QWidget();

    widget->show();

     SmallClass* smallWidget =new SmallClass(widget);

    smallWidget->setStyleSheet("background-color : rgba(100,255,255,255)");

    smallWidget->setGeometry(0,0,300,300);

    smallWidget->show();

    return a.exec();

}


this is SmallClass.h


class SmallClass : public QWidget

{

    Q_OBJECT

public:

    explicit SmallClass(QWidget *parent = 0);

};


in cpp

SmallClass::SmallClass(QWidget *parent) :

    QWidget(parent)

{}


There should be a blue widget in the up-left corner of the parent
widget. But in fact there is not. But if I change into  QWidget*
smallWidget =new QWidget (widget);

It will be OK( a blue widget appears). So can you tell me why this
happens? Really thanks very much!!!



-- 
Best regards
Li Zhongmiao
Digital Media, College of Computer Science, Zhejiang University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101212/6fc09625/attachment.html 


More information about the Qt-interest-old mailing list