谢谢啊 问题解决了,应该是把QVBoxLayout* rightlayout = new QVBoxLayout ;改为QVBoxLayout* rightlayout = new QVBoxLayout(this);就可以,我基本上是照着《C++ GUI QT3 编程》这本书140页写的。 现在发现书上的也不一定对啊。
但是现在新问题又出现了,我想把MainWindow()构造函数的内容换为:
QLabel *label = new QLabel("Timer Interval",this);
QwtCounter *counter = new QwtCounter(this);
counter->setRange(0.0,100.0,1.0);
QHBoxLayout *layoutfirst = new QHBoxLayout(this);
layoutfirst->addWidget( label );
layoutfirst->addWidget( counter );
QVBoxLayout *leftlayout = new QVBoxLayout(this);
leftlayout->addLayout( layoutfirst );
QPushButton* Start = new QPushButton( this,"Start" );
Start->setText( tr( "&Start" ) );
QPushButton* Stop = new QPushButton( this,"Stop" );
Stop->setText( tr( "&Stop" ) );
QPushButton* Quit = new QPushButton( this,"Quit" );
Quit->setText( tr( "&Quit" ) );
QVBoxLayout* rightlayout = new QVBoxLayout(this);
rightlayout->addWidget( Start);
rightlayout->addWidget( Stop );
rightlayout->addWidget( Quit );
QHBoxLayout* mainlayout = new QHBoxLayout(this);
mainlayout->setMargin(11);
mainlayout->setSpacing(6);
mainlayout->addLayout(rightlayout);
mainlayout->addLayout(leftlayout);
我主要想实现一下多重的这种布局嵌套,但是好像出不来我想要的布局,很纠结,不知道为啥,为毕设,在这块已经耗掉了我快整整两周了。大侠帮忙解答下为啥啊。