//MyWidget.h
#pragma once
#include <QWidget>
#include <QPushButton>
class MyWidget:public QWidget
{
Q_OBJECT
public:
MyWidget();
public:
QPushButton m_btnQuit;
QPushButton m_btnTest;
public slots:
void runTestDialog();
};
//MyDialog.cpp
#include "MyDialog.h"
MyDialog::MyDialog(QWidget* parent,Qt::WindowFlags f)
:QDialog(parent,f)
{
m_pLayout = new QGridLayout(this);
this->setWindowTitle(tr("run Test Dialog"));
//this->setFixedHeight(200);
this->setFixedWidth(640);
m_pbtnQuit = new QPushButton("Quit");
m_pbtnTestQFileDialog = new QPushButton("Test QFileDialog");
m_pbtnTestQFileDialog->setFixedWidth(150);
m_pbtnTestQColorDialog = new QPushButton("Test QColorDialog");
m_pbtnTestQFontDialog = new QPushButton("Test QFontDialog");
m_pFrameColor = new QFrame;
m_pFrameColor->setFrameShape(QFrame::Box);
m_pFrameColor->setAutoFillBackground(true);
m_pEditFile = new QLineEdit;
//m_pEditFile->resize(200,20);
m_pEditFont = new QLineEdit;
m_pEditFont->setText( trUtf8("\xE5\xAD\x97\xE4\xBD\x93\xE6\xB5\x8B\xE8\xAF\x95 Font Test"));
//m_pEditFont->setMinimumHeight(40);
m_pLayout->addWidget(m_pbtnTestQFileDialog,0,0);
m_pLayout->addWidget(m_pEditFile,0,1);
m_pLayout->addWidget(m_pbtnTestQColorDialog,1,0);
m_pLayout->addWidget(m_pFrameColor,1,1);
m_pLayout->addWidget(m_pbtnTestQFontDialog,2,0);
m_pLayout->addWidget(m_pEditFont,2,1);
m_pLayout->addWidget(m_pbtnQuit,5,0);
m_pLayout->setMargin(15);
m_pLayout->setSpacing(10);
connect(m_pbtnQuit,SIGNAL(clicked()),qApp,SLOT(quit()) );
connect(m_pbtnTestQFileDialog,SIGNAL(clicked()),SLOT(TestQFileDialog()) );
connect(m_pbtnTestQColorDialog,SIGNAL(clicked()),SLOT(TestQColorDialog()) );
connect(m_pbtnTestQFontDialog,SIGNAL(clicked()),SLOT(TestQFontDialog()) );
}
void MyDialog::TestQFileDialog()
{
QProgressDialog* pDlg = new QProgressDialog(this);
int nMax = 100001;
pDlg->setLabelText("Test QProgressDialog");
pDlg->setRange(0,nMax-1);
//pDlg->setModal(false);
pDlg->setAutoClose(true);
pDlg->show();
//pDlg->exec();
for (int i=0;i<nMax;i++)
{
if (pDlg->wasCanceled())
{
qDebug() << pDlg->wasCanceled();
break;
}
pDlg->setValue(i);
qApp->processEvents();
//if (i==50000)
//{
// pDlg->close();
// break;
//}
}
delete pDlg;
//QString hello = tr("Hello");
//QString world = tr("World");
//QMessageBox::information(this,hello,world);
//QString filename = QFileDialog::getOpenFileName(this,"Test QFileDialog","/","C++ files(*.cpp)");
//m_pEditFile->setText(filename);
}
void MyDialog::TestQColorDialog()
{
QColor color = QColorDialog::getColor();
if (color.isValid())
{
m_pFrameColor->setPalette(color);
}
}
void MyDialog::TestQFontDialog()
{
bool ok;
QFont font = QFontDialog::getFont(&ok);
if (ok)
{
//font.setPointSize(24);
m_pEditFont->setFont(font);
}
}