标题:【提问】如何做…按一button…彈出一個視窗
作者:btopcst
日期:2005-11-26 08:38
内容:
///////////////////////qt.h//////////////////////////////
#ifndef MY_WIDGET_H
#define MY_WIDGET_H
#include
#include
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QPushButton;
class my_widget : public QDialog
{
Q_OBJECT
public:
my_widget( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
~my_widget();
QPushButton* pushButton;
protected:
protected slots:
virtual void languageChange();
};
#endif // MY_WDGET_H
/////////////////////////////////qt.cpp///////////////////////////////
#include "qt.h"
#include
#include
#include
#include
#include
my_widget::my_widget( QWidget* parent, const char* name, bool modal, WFlags fl )
: QDialog( parent, name, modal, fl )
{
pushButton = new QPushButton( this, "pushButton" );
pushButton->setGeometry( QRect( 120, 150, 121, 41 ) );
languageChange();
}
my_widget::~my_widget()
{
}
void my_widget::languageChange()
{
setCaption( tr( "QT" ) );
pushButton->setText( tr( "Button" ) );
}
///////////////////////////////main.cpp/////////////////////////
#include
#include"qt.h"
int main(int argc,char **argv)
{
QApplication app(argc,argv);
my_widgetmw;
app.setMainWidget(&mw);
mw.resize(352,288);
mw.show();
return app.exec();
}
////////////////////問題//////////////////////////////////
上面三個程式…只是在一個視窗裡放一個button…
我想要做的是…如何在按下button後…再彈出一個視窗…
如果會的話…能否教我…謝謝
#1 [fanyu 11-26 10:31]
Untitled
#ifndef MY_WIDGET_H
#define MY_WIDGET_H
#include
#include
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QPushButton;
class my_widget : public QWidget
{
Q_OBJECT
public:
my_widget( QWidget* parent = 0,Qt::WFlags fl = 0 );
~my_widget();
QPushButton* pushButton;
protected:
protected slots:
virtual void languageChange();
public slots:
void ShowForm();
};
#endif // MY_WDGET_H
#2 [fanyu 11-26 10:31]
Untitled
/////////////////////////////////qt.cpp///////////////////////////////
#include "qt.h"
#include
#include
#include
#include
#include
#include
#include
my_widget::my_widget( QWidget* parent, Qt::WFlags fl )
: QWidget( parent, fl )
{
pushButton = new QPushButton( "pushButton",this );
pushButton->setGeometry( QRect( 120, 150, 121, 41 ) );
languageChange();
QObject::connect( pushButton, SIGNAL(clicked()), this, SLOT(ShowForm()) );
}
my_widget::~my_widget()
{
}
void my_widget::languageChange()
{
pushButton->setText( tr( "Button" ) );
}
void my_widget::ShowForm()
{
QMessageBox *a=new QMessageBox(this);
a->about(this,"111","ddd");
}
#3 [fanyu 11-26 10:32]
Untitled
///////////////////////////////main.cpp/////////////////////////
#include
#include"qt.h"
int main(int argc,char **argv)
{
QApplication app(argc,argv);
my_widget mw;
mw.resize(352,288);
mw.show();
return app.exec();
}
#4 [fanyu 11-26 10:34]
以上代码是Qt 4的代码,在MingW下编译通过。
#5 [fanyu 11-26 10:53]
qt 4的运行库在ftp站点上有。