我用的是qt3,目的是要弄一个像Example中Extension那样的扩展界面。我先用designer画了一个dialog窗口,只有一个按钮,再画了一个widget,里面有label什么的,然后用uic和moc生成了这个widget的.h 和 .cpp文件,最后添加槽。可运行后,怎么点按钮都不能show出来这个需要扩展的widget,查了下说widget必须有布局,但我弄了布局也还是不行。请问大家是什么原因啊。。本人QT新手,请大家帮忙。。以下是相关文件:
///// testdialogimpl.h ///////
#include "testdialog.h"
class Form;
class testDialogImpl : public testDialog
{
Q_OBJECT
public:
testDialogImpl( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags f = 0 );
Form *ttt;
bool ext;
public slots:
void newSlot();
};
///// testdialogimpl.cpp ///////
#include "testdialogimpl.h"
#include "form.h"
#include "qpushbutton.h"
testDialogImpl::testDialogImpl( QWidget* parent, const char* name, bool modal, WFlags f )
: testDialog( parent, name, modal, f )
{
ext = FALSE;
ttt = new Form;
setExtension( ttt );
setOrientation( Vertical );
}
void testDialogImpl::newSlot()
{
ext = !ext;
showExtension(ext);
}
testdialog.h 和 .cpp就不贴了,里面connect了按钮和槽NewSlot。
///// form.h ///////
#ifndef FORM1_H
#define FORM1_H
#include <qvariant.h>
#include <qwidget.h>
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QSpacerItem;
class QLabel;
class QLineEdit;
class QPushButton;
class Form : public QWidget
{
Q_OBJECT
public:
Form( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
~Form();
QLabel* TextLabel1;
QLineEdit* logfileLineEdit;
QPushButton* browsePushButton;
protected:
QHBoxLayout* Layout6;
protected slots:
virtual void languageChange();
};
#endif // FORM1_H
///// form.cpp ///////
#include "form.h"
#include <qvariant.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
Form::Form( QWidget* parent, const char* name, WFlags fl )
: QWidget( parent, name, fl )
{
if ( !name )
setName( "Form1" );
QWidget* privateLayoutWidget = new QWidget( this, "Layout6" );
privateLayoutWidget->setGeometry( QRect( 20, 40, 236, 25 ) );
Layout6 = new QHBoxLayout( privateLayoutWidget, 11, 6, "Layout6");
TextLabel1 = new QLabel( privateLayoutWidget, "TextLabel1" );
Layout6->addWidget( TextLabel1 );
logfileLineEdit = new QLineEdit( privateLayoutWidget, "logfileLineEdit" );
logfileLineEdit->setFrameShape( QLineEdit::LineEditPanel );
logfileLineEdit->setFrameShadow( QLineEdit::Sunken );
Layout6->addWidget( logfileLineEdit );
browsePushButton = new QPushButton( privateLayoutWidget, "browsePushButton" );
Layout6->addWidget( browsePushButton );
languageChange();
resize( QSize(258, 129).expandedTo(minimumSizeHint()) );
clearWState( WState_Polished );
TextLabel1->setBuddy( logfileLineEdit );
}
Form::~Form()
{
}
void Form::languageChange()
{
setCaption( tr( "Form1" ) );
TextLabel1->setText( tr( "Log &File" ) );
browsePushButton->setText( tr( "&Browse..." ) );
}