#ifndef FINDFILEDIALOG_H
#define FINDFILEDIALOG_H
#include <QDialog>
class QCheckBox;
class QLabel;
class QLineEdit;
class QPushButton;
class QTableWidget;
class FindFileDialog : public QDialog
{
Q_OBJECT
public:
FindFileDialog(QWidget *parent = 0);
private:
QLabel *namedLabel;
QLabel *lookInLabel;
QLineEdit *lookInLineEdit;
QLineEdit *namedLineEdit;
QCheckBox *subfoldersCheckBox;
QTableWidget *tableWidget;
QLabel *messageLabel;
QPushButton *findButton;
QPushButton *stopButton;
QPushButton *closeButton;
QPushButton *helpButton;
};
#endif
#include <QtGui>
#include "findfiledialog.h"
FindFileDialog::FindFileDialog(QWidget *parent)
: QDialog(parent)
{
namedLabel = new QLabel(tr("&Named:"), this);
namedLineEdit = new QLineEdit(this);
namedLabel->setBuddy(namedLineEdit);
lookInLabel = new QLabel(tr("&Look in:"), this);
lookInLineEdit = new QLineEdit(this);
lookInLabel->setBuddy(lookInLineEdit);
subfoldersCheckBox = new QCheckBox(tr("Include subfolders"), this);
QStringList labels;
labels << tr("Name") << tr("In Folder") << tr("Size")
<< tr("Modified");
tableWidget = new QTableWidget(this);
tableWidget->setColumnCount(4);
tableWidget->setHorizontalHeaderLabels(labels); //怎样为QTableWidget 或者QLineView加表头 实现方法
messageLabel = new QLabel(tr("0 files found"), this);
messageLabel->setFrameShape(QLabel::Panel);
messageLabel->setFrameShadow(QLabel::Sunken); //尾部的显示
findButton = new QPushButton(tr("&Find"), this);
stopButton = new QPushButton(tr("Stop"), this);
closeButton = new QPushButton(tr("Close"), this);
helpButton = new QPushButton(tr("Help"), this);
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
namedLabel->setGeometry(9, 9, 50, 25); //从屏幕上(9,9)位置开始(即为最左上角的点),显示一个50*25的界面(宽50,高25)
namedLineEdit->setGeometry(65, 9, 200, 25);
lookInLabel->setGeometry(9, 40, 50, 25);
lookInLineEdit->setGeometry(65, 40, 200, 25);
subfoldersCheckBox->setGeometry(9, 71, 256, 23);
tableWidget->setGeometry(9, 100, 256, 100);
messageLabel->setGeometry(9, 206, 256, 25);
findButton->setGeometry(271, 9, 85, 32);
stopButton->setGeometry(271, 47, 85, 32);
closeButton->setGeometry(271, 84, 85, 32);
helpButton->setGeometry(271, 199, 85, 32);
setWindowTitle(tr("Find Files or Folders"));
setFixedSize(365, 240);
}
#include <QApplication>
#include "findfiledialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
FindFileDialog dialog;
dialog.show();
return app.exec();
}
#ifndef FINDFILEDIALOG_H#define FINDFILEDIALOG_H#include <QDialog>class QCheckBox;class QLabel;class QLineEdit;class QPushButton;class QTableWidget;class FindFileDialog : public QDialog{Q_OBJECTpublic:
FindFileDialog(QWidget *parent = 0);protected:
void resizeEvent(QResizeEvent *event);//虚函数的重构,当窗口的大小发生变化时,QT会自动执行的函数private:
QLabel *namedLabel;QLabel *lookInLabel;QLineEdit *lookInLineEdit;QLineEdit *namedLineEdit;QCheckBox *subfoldersCheckBox;QTableWidget *tableWidget;QLabel *messageLabel;QPushButton *findButton;QPushButton *stopButton;QPushButton *closeButton;QPushButton *helpButton;};#endif
#include <QtGui>#include "findfiledialog.h"FindFileDialog::FindFileDialog(QWidget *parent): QDialog(parent){namedLabel = new QLabel(tr("&Named:"), this);namedLineEdit = new QLineEdit(this);namedLabel->setBuddy(namedLineEdit);lookInLabel = new QLabel(tr("&Look in:"), this);lookInLineEdit = new QLineEdit(this);lookInLabel->setBuddy(lookInLineEdit);subfoldersCheckBox = new QCheckBox(tr("Include subfolders"), this);QStringList labels;labels << tr("Name") << tr("In Folder") << tr("Size")<< tr("Modified");tableWidget = new QTableWidget(this);tableWidget->setColumnCount(4);tableWidget->setHorizontalHeaderLabels(labels);messageLabel = new QLabel(tr("0 files found"), this);messageLabel->setFrameShape(QLabel::Panel);messageLabel->setFrameShadow(QLabel::Sunken);findButton = new QPushButton(tr("&Find"), this);stopButton = new QPushButton(tr("Stop"), this);closeButton = new QPushButton(tr("Close"), this);helpButton = new QPushButton(tr("Help"), this);connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));setWindowTitle(tr("Find Files or Folders"));setMinimumSize(265, 190);//设置最小的大小resize(365, 240);//设置刚开始的大小}void FindFileDialog::resizeEvent(QResizeEvent * /* event */){int extraWidth = width() - minimumWidth();int extraHeight = height() - minimumHeight();namedLabel->setGeometry(9, 9, 50, 25);namedLineEdit->setGeometry(65, 9, 100 + extraWidth, 25);lookInLabel->setGeometry(9, 40, 50, 25);lookInLineEdit->setGeometry(65, 40, 100 + extraWidth, 25);subfoldersCheckBox->setGeometry(9, 71, 156 + extraWidth, 23);tableWidget->setGeometry(9, 100, 156 + extraWidth,50 + extraHeight);messageLabel->setGeometry(9, 156 + extraHeight, 156 + extraWidth,25);findButton->setGeometry(171 + extraWidth, 9, 85, 32);stopButton->setGeometry(171 + extraWidth, 47, 85, 32);closeButton->setGeometry(171 + extraWidth, 84, 85, 32);helpButton->setGeometry(171 + extraWidth, 149 + extraHeight, 85,32);}