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 ...
随机推荐
- Luogu 4844 LJJ爱数数
LOJ 6482 设$d = gcd(a, b)$,$xd = a$,$yd = b$,因为$\frac{1}{a} + \frac{1}{b} = \frac{a + b}{ab} = \frac{ ...
- Ubuntu安装开发版pidgin支持lwqq插件
sudo add-apt-repository ppa:lainme/pidgin-lwqq """添加pidgin-lwqq源""" s ...
- [原创]java:Stream、Socket等源码分析
一.对于java启动之后的线程的说明 java在启动后会有几个特殊线程: 1.main线程,主线程 2.JVM线程,虚拟机的线程 3.GC垃圾回收线程,是个守护线程 4.EDT&Toolkit ...
- .net Stream篇(五)
MemoryStream 目录: 1 简单介绍一下MemoryStream 2 MemoryStream和FileStream的区别 3 通过部分源码深入了解下MemoryStream 4 分析Mem ...
- .net Stream篇(四)
FileStream 目录: 如何去理解FileStream? FileStream的重要性 FileStream常用构造函数(重要) 非托管参数SafeFileHandle简单介绍 FileStre ...
- .net 3.5 Lambda表达式
Lambda表达式 转自http://www.cnblogs.com/kingmoon/archive/2011/05/03/2035696.html "Lambda表达式"是一个 ...
- NPOI row.Cells[i] 的坑
我有A行B列的EXCEL表格: 获取一行数据: IRow row=sheet.GetRow(i); 正常是这样的 row.Cells.Count = B; 但由于会存在没有激活的单元格,导致 row. ...
- conda install 安装太慢怎么办?
小编我在安装tensorflow和keras的过程中,安装进程太慢,小木棍一直在转圈...抓狂... 如何解决??? 使用清华提供的anaconda镜像,使用以后真的很快! Anaconda 镜像使用 ...
- day02.1-字符串内置方法
字符串——str的定义:test = "zizaijiapu" 特点:1. 字符串是可迭代对象: 2. 字符串中各元素是有序的: 3. 字符串一经创建,其内容值不可修改. 1. 查 ...
- leetcode 106. 从中序与后序遍历序列构造二叉树(Construct Binary Tree from Inorder and Postorder Traversal)
目录 题目描述: 示例: 解法: 题目描述: 根据一棵树的中序遍历与后序遍历构造二叉树. 注意: 你可以假设树中没有重复的元素. 示例: 给出 中序遍历 inorder = [9,3,15,20,7] ...