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 4869 albus就是要第一个出场
BZOJ 2844 被NOIP模拟赛题弄自闭了QuQ. 因为本题要求异或,所以自然地构造出线性基,假设本题中给出的数有$n$个,而我们构造出的线性基大小为$m$,那么每一个可以异或出来的数相当于出现了 ...
- URAL 1141. RSA Attack(欧拉定理+扩展欧几里得+快速幂模)
题目链接 题意 : 给你n,e,c,并且知道me ≡ c (mod n),而且n = p*q,pq都为素数. 思路 : 这道题的确与题目名字很相符,是个RSA算法,目前地球上最重要的加密算法.RSA算 ...
- Django工程中使用echarts怎么循环遍历显示数据
前言: 后面要开发测试管理平台,需要用到数据可视化,所以研究了一下 先看下最后的图吧,单击最上方的按钮可以控制柱状图显隐 views.py # -*- coding: utf-8 -*- from _ ...
- ASP.NET Session原理及处理方法
session是怎么存储,提取的 1.在服务器端有一个session池,用来存储每个用户提交session中的数据,Session对于每一个客户端(或者说浏览器实例)是“人手一份”,用户首次与Web服 ...
- NSNotification 消息通知的3种方式
1.Notification Center的概念: 它是一个单例对象,允许当事件发生时通知一些对象,让对象做出相应反应. 它允许我们在低程度耦合的情况下,满足控制器与一个任意的对象进行通信的目的. 这 ...
- 857. Minimum Cost to Hire K Workers
There are N workers. The i-th worker has a quality[i] and a minimum wage expectation wage[i]. Now w ...
- 加密模块(md5)
一.md5加密 import hashlib s = ' print(s.encode()) m = hashlib.md5(s.encode())# 必须得传一个bytes类型的 print(m.h ...
- logging、hashlib、collections模块
一.hashlib模块(加密模块) 1.什么叫hash:hash是一种算法(3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 , ...
- SDUT OJ 数据结构实验之二叉树五:层序遍历
数据结构实验之二叉树五:层序遍历 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...
- SDUT OJ 数据结构实验之链表三:链表的逆置
数据结构实验之链表三:链表的逆置 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...