C++ GUI Qt4编程(12)-6.1FindFileDialog
1. 主要介绍了QGridLayout, QHBoxLayout, QVBoxLayout3种布局管理器的使用方法。
2. 在linux中,继承自QDialog的对话框,没有最大化、最小化、关闭按钮,如果需要这3个按钮,
需要增加: setWindowFlags(Qt::Widget);
在windows中,即使不加:setWindowFlags(Qt::Widget); 也会有最大化、最小化、关闭按钮。
3. findfiledialog.h
/**/
#ifndef FINDFILEDIALOG_H
#define FINDFILEDIALOG_H #include <QDialog> class QLabel;
class QLineEdit;
class QPushButton;
class QCheckBox;
class QTableWidget;
class QHBoxLayout;
class QVBoxLayout;
class QGridLayout; class FindFileDialog : public QDialog
{
Q_OBJECT public:
FindFileDialog(QWidget *parent = ); private:
QLabel *namedLabel;
QLabel *lookInLabel;
QLineEdit *namedLineEdit;
QLineEdit *lookInLineEdit;
QCheckBox *subfoldersCheckBox;
QTableWidget *tableWidget;
QLabel *messageLabel; QPushButton *findButton;
QPushButton *stopButton;
QPushButton *closeButton;
QPushButton *helpButton; QGridLayout *leftLayout;
QVBoxLayout *rightLayout;
QHBoxLayout *mainLayout;
}; #endif
4. findfiledialog.cpp
/**/
#include "findfiledialog.h" #include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QCheckBox>
#include <QTableWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout> FindFileDialog::FindFileDialog(QWidget *parent)
: QDialog(parent)
{
namedLabel = new QLabel(tr("&Named:"));
namedLineEdit = new QLineEdit;
namedLabel->setBuddy(namedLineEdit); lookInLabel = new QLabel(tr("&Look in:"));
lookInLineEdit = new QLineEdit;
lookInLabel->setBuddy(lookInLineEdit); subfoldersCheckBox = new QCheckBox(tr("Include subfolders")); QStringList labels;
labels << tr("Name") << tr("In Folder")
<< tr("Size") << tr("Modified"); tableWidget = new QTableWidget;
tableWidget->setColumnCount();
tableWidget->setHorizontalHeaderLabels(labels); messageLabel = new QLabel(tr("0 files found"));
messageLabel->setFrameShape(QFrame::Panel);
messageLabel->setFrameShadow(QFrame::Sunken); /* QGridLayout
void addWidget(QWidget * widget,
int fromRow,int fromColumn,
int rowSpan,int columnSpan,
Qt::Alignment alignment = 0)
*/
leftLayout = new QGridLayout;
leftLayout->addWidget(namedLabel, , );
leftLayout->addWidget(namedLineEdit, , );
leftLayout->addWidget(lookInLabel, , );
leftLayout->addWidget(lookInLineEdit, , );
/*subfoldersCheckBox的位置坐标(2, 0),占1行,占2列*/
leftLayout->addWidget(subfoldersCheckBox, , , , );
leftLayout->addWidget(tableWidget, , , , );
leftLayout->addWidget(messageLabel, , , , ); findButton = new QPushButton(tr("&Find"));
stopButton = new QPushButton(tr("&Stop"));
closeButton = new QPushButton(tr("&Close"));
helpButton = new QPushButton(tr("&Help")); connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); rightLayout = new QVBoxLayout;
rightLayout->addWidget(findButton);
rightLayout->addWidget(stopButton);
rightLayout->addWidget(closeButton);
rightLayout->addStretch();
rightLayout->addWidget(helpButton); mainLayout = new QHBoxLayout;
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout); setLayout(mainLayout);
setWindowTitle(tr("Find Files or Folders"));
/*在linux中,继承自QDialog的对话框没有最大化最小化和关闭按钮*/
setWindowFlags(Qt::Widget); /*在linux中让对话框有最大最小和关闭按钮*/
}
5. main.cpp
/**/
#include <QApplication>
#include "findfiledialog.h" int main(int argc, char *argv[])
{
QApplication app(argc, argv); FindFileDialog dialog;
dialog.show(); return app.exec();
}
6. 不带关闭按钮:

带关闭按钮:

C++ GUI Qt4编程(12)-6.1FindFileDialog的更多相关文章
- C++ GUI Qt4编程(10)-3.4spreadsheet
1. C++ GUI Qt4编程第三章,增加spreadsheet. 2. spreadsheet.h /**/ #ifndef SPREADSHEET_H #define SPREADSHEET_H ...
- C++ GUI Qt4编程(09)-3.3spreadsheet-toolbar
1. C++ GUI Qt4编程第三章,增加工具栏.状态栏和快捷键. 2. mainwindow.h /**/ #ifndef MAINWINDOW_H #define MAINWINDOW_H #i ...
- C++ GUI Qt4编程(08)-3.2spreadsheet-resource
1. C++ GUI Qt4编程第三章,图片使用资源机制法. 2. 步骤: 2-1. 在resource文件夹下,新建images文件,存放图片. 2-2. 新建spreadsheet.qrc文件,并 ...
- C++ GUI Qt4编程(07)-3.1menu
1. C++ GUI Qt4编程第三章,添加menu菜单. 2. mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include < ...
- C++ GUI Qt4编程(03)-1.3layout
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:layout.cpp #include <QApplication> #i ...
- C++ GUI Qt4编程(02)-1.2quit
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:quit.cpp #include <QApplication> #inc ...
- C++ GUI Qt4编程(01)-1.1Hello Qt
1. 根据C++ GUI Qt4编程(第二版)整理2. 系统:centos7: Qt版本:5.5.13. 程序:hello.cpp #include <QApplication> #in ...
- C++ GUI Qt4编程-创建自定义窗口部件
C++ GUI Qt4编程-创建自定义窗口部件 Qtqt4 通过Qt窗口部件进行子类化或者直接对QWidget进行子类化,就可以创建自定义窗口部件,下面示范两种方式,并且也会说明如何把自定义窗口部 ...
- C++ GUI Qt4 编程 (第二版)
[加拿大]JasminBlanchette [英]MarkSummerfield . 电子工业 2008. 前几天的问题多是因为版本不兼容的问题. QT本身Q4 Q5就有版本问题,然后集成到VS08 ...
随机推荐
- Django-----restframework图解
- mongodb数据库学习【安装及简单增删改查】
//@desn:mongodb数据库学习 //@desn:码字不宜,转载请注明出处 //@author:张慧源 <turing_zhy@163.com> //@date:2018/08/ ...
- Listview 利用Datapager进行分页
原文:http://lgm9128.blog.163.com/blog/static/421734292010513111851101/ <asp:ListView ID="ListV ...
- .net core MVC 通过 Filters 过滤器拦截请求及响应内容
前提: 需要nuget Microsoft.Extensions.Logging.Log4Net.AspNetCore 2.2.6: Swashbuckle.AspNetCore 我暂时用的是 ...
- Castle Windsor 注册组件
1.逐个注册组件即对每个接口通过代码指定其实现类,代码: container.Register( Component.For<IMyService>() //接口 .Implemented ...
- iOS系统各个版本的占比查询
目的:为了向大多数看齐,我们要实时了解应用系统的使用占比 1.苹果官网查询各个系统的占比: Apple 2.各种设备各种系统的占比 第三方
- "window.location.href"、"location.href"是本页面跳转
"window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...
- Axios 使用说明
get请求: on_sum: function () { axios.get('http://127.0.0.1:8000/test/' ).then(response=>{ alert('ok ...
- mybatis 学习笔记(三):mapper 代理开发 dao 层
mybatis 学习笔记(三):mapper 代理开发 dao 层 优势 通过使用mapper 代理,我们可以不需要去编写具体的实现类(使用 getMapper() 方法自动生成),只需编写接口即可, ...
- 洛谷P2763 试题库问题(最大流)
传送门 网络流界的一股清流啊……终于没那么变态了…… 考虑一下怎么建图.对于每一个类型,我们从$S$向他连边,容量为它所需的题数,表明它要可以有这么多题,对于每一道题目,我们从它对应的类型向他连边,容 ...