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 ...
随机推荐
- cbv+resful+APIView源码分析
CBV源码分析 1概念:什么是cbv和fbv 已经什么是API class bass View ---基于类的视图 function bass View ---基于函数的视图 API(Applicat ...
- Jmeter接口测试-新用户注册API
新用户注册 新用户注册的接口是POST /register username/password/password_confirmation 该接口需要提供3个参数,分别是 username 用户名 p ...
- oracle数据库之数据插入、修改和删除
作为一合格的测试人员对数据库的单表查询.多表查询.分组查询.子查询等等这些基本查询方法还是要会的.不然到企业中,容易被一些人鄙视,或者说如果数据库学不好,表查不明白,那么对自己能力来说也是一种侮辱,因 ...
- [bash] 显示配色
#/bin/bash for STYLE in 0 1 2 3 4 5 6 7; do for FG in 30 31 32 33 34 35 36 37; do for BG in 40 41 42 ...
- C#@的用法
string path = @"C:\Windows\"; // 如果不加 @,编译会提示无法识别的转义序列 // 如果不加 @,可以写成如下 string path2 = &qu ...
- 四、命令行模式和Node交互模式
请注意区分命令行模式和Node交互模式. 看到类似C:\>是在Windows提供的命令行模式: 在命令行模式下,可以执行node进入Node交互式环境,也可以执行node hello.js运行一 ...
- [转]解读Unity中的CG编写Shader系列3——表面剔除与剪裁模式
在上一个例子中,我们得到了由mesh组件传递的信息经过数学转换至合适的颜色区间以颜色的形式着色到物体上.这篇文章将要在此基础上研究片段的擦除(discarding fragments)和前面剪裁.后面 ...
- c语言指针的简单实例
c语言的指针的存在使得c语言对硬件的操控,以及灵活性得到了极大的提高. 但是指针的使用存在着很多难点问题. #include<stdlib.h> #include<stdio.h&g ...
- oracle为IN OUT变量或OUT变量赋值时提示“表达式''不能用作赋值目标”
是因为IN OUT变量和OUT变量是要输出的,不能赋给它常量值,这样它就不能再被赋值而输出了,所以是禁止赋常量值的,比如''也是常量值,也不可以赋给这两种类型的变量,如果不能把存储过程中的其他变量赋给 ...
- C# Winform中自定义筛选及自带统计行的Datagridview控件
网上分享有很多种自制DGV控件,都有不小的缺陷. 没办法,按需求自己定制了一个. 一.过滤方面类似于Excel的筛选功能.支持右键菜单筛选,同时也支持在文本框输入文字按焦点列进行筛选: 二.统计行我采 ...