[Qt-interest] can not set Layout correctly

yanqzhi at gmail.com yanqzhi at gmail.com
Wed Aug 25 09:29:16 CEST 2010


I hnow that If there already is a layout manager installed on this widget, QWidget 
won't let you install another.

But I do not set layout in the MyDialog and other class except for in the class 
TestDialog's constructor;

I want to hnow how set layout correctly!

Thanks!

Sincerely yours, 

yanqzhi at gmail.com 
2010-08-25 

======= 2010-08-25 15:02, your message: Re: [Qt-interest] can not set Layout correctly======= 

Den 25-08-2010 08:15, yanqzhi at gmail.com skrev: 
> *I have a class subclass QDialog* 
> 
> class MyDiaolog : public QDialog 
> { 
> Q_OBJECT 
> 
> public: 
> MyDiaolog(QWidget *parent = NULL); 
> ~MyDiaolog(); 
> 
> protected: 
> QPushButton * mButton; 
> QGridLayout * mLayout; 
> }; 
> 
> *in the constructor* 
> 
> MyDiaolog::MyDiaolog(QWidget *parent) 
> : QDialog(parent) 
> { 
> mButton = new QPushButton("testButton", this); 
> mLayout = new QGridLayout(this); 
> mLayout->addWidget(mButton, 0, 0, 1, 1); 
> } 
> 
> *and I have another class which subclass the class MyDialog* 
> 
> class TestDialog : public MyDiaolog 
> { 
> Q_OBJECT 
> 
> public: 
> TestDialog(QWidget *parent = NULL); 
> ~TestDialog (); 
> 
> private: 
> QPushButton * mButton1; 
> QGridLayout * mRightLayou; 
> QHBoxLayout * mHLayout; 
> }; 
> 
> *int the constructor* 
> 
> Dialog::Dialog(QWidget *parent) 
> : MyDiaolog(parent) 
> { 
> mButton1 = new QPushButton("right", this); 
> mRightLayou = new QGridLayout(this); 
> mRightLayou->addWidget(mButton1, 0, 0, 1, 1); 
> 
> mHLayout = new QHBoxLayout(this); 
> mHLayout->addLayout(mLayout); 
> mHLayout->addLayout(mRightLayou); 
> 
> setLayout(mHLayout); 
> } 
> 
> I expect that the buttons layout side by side from left to right, 
> but in fact the TestDialog's layout() return the mLayout; 
> 
> How can I set the TestDialog's layout as mHlayout? 

>From the setLayout() documentation: 

If there already is a layout manager installed on this widget, QWidget 
won't let you install another. You must first delete the existing layout 
manager. 

Bo. 

-- 

Bo Thorsen, Fionia Software 
Expert Qt and C++ developer for hire 
Mail me if you need a hand with your Qt code 
_______________________________________________ 
Qt-interest mailing list 
Qt-interest at trolltech.com 
http://lists.trolltech.com/mailman/listinfo/qt-interest 
. 


= = = = = = = = = = = = = = = = = = = = 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100825/dc7a23b2/attachment.html 


More information about the Qt-interest-old mailing list