[Qt-interest] can not set Layout correctly
Bo Thorsen
bo at fioniasoftware.dk
Wed Aug 25 09:02:23 CEST 2010
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
More information about the Qt-interest-old
mailing list