feat: QTreeWidget and QDockWidget
QTreeWidget(目录树组件) and QDockWidget(停靠区域组件)的介绍和使用
298
QtQTreeWidgetEx/ExQTreeWidget.cpp
Normal file
@ -0,0 +1,298 @@
|
|||||||
|
#include "ExQTreeWidget.h"
|
||||||
|
#include "ui_ExQTreeWidget.h"
|
||||||
|
|
||||||
|
ExQTreeWidget::ExQTreeWidget(QWidget *parent) :
|
||||||
|
QMainWindow(parent),
|
||||||
|
ui(new Ui::ExQTreeWidget)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
setWindowTitle(QObject::tr("QTreeWidget和QDockWidget的讲解和使用"));
|
||||||
|
|
||||||
|
setCentralWidget(ui->scrollArea); //设置scrollArea为中心控件
|
||||||
|
initTree();
|
||||||
|
|
||||||
|
m_labFlie = new QLabel("当前文件的路径:", this);
|
||||||
|
ui->statusBar->addWidget(m_labFlie);
|
||||||
|
}
|
||||||
|
|
||||||
|
ExQTreeWidget::~ExQTreeWidget()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
//初始化根节点(只能够有唯一)
|
||||||
|
void ExQTreeWidget::initTree()
|
||||||
|
{
|
||||||
|
//准备工作
|
||||||
|
ui->treeFiles->clear();
|
||||||
|
QString dataStr = "";
|
||||||
|
QIcon icon;
|
||||||
|
icon.addFile(":/image/Image001.jpg");
|
||||||
|
|
||||||
|
//创建唯一root的节点
|
||||||
|
QTreeWidgetItem* root = new QTreeWidgetItem(treeItemType::itemRoot);
|
||||||
|
root->setIcon(treeColNum::colItem, icon);
|
||||||
|
root->setText(treeColNum::colItem, QString("相簿"));
|
||||||
|
root->setText(treeColNum::colItemType, QString("treeItemType"));
|
||||||
|
root->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsAutoTristate);
|
||||||
|
root->setCheckState(treeColNum::colItem, Qt::Unchecked);
|
||||||
|
root->setData(treeColNum::colItem, Qt::UserRole, QVariant(dataStr));
|
||||||
|
|
||||||
|
//添加顶层节点
|
||||||
|
ui->treeFiles->addTopLevelItem(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加目录节点
|
||||||
|
void ExQTreeWidget::addFolderItem(QTreeWidgetItem *parItem, QString dirName)
|
||||||
|
{
|
||||||
|
QIcon icon;
|
||||||
|
icon.addFile(":/image/Image006.jpg");
|
||||||
|
|
||||||
|
//添加一个新的节点
|
||||||
|
QTreeWidgetItem* item = new QTreeWidgetItem(treeItemType::itemFile);
|
||||||
|
QString folderName = getFinalFolderName(dirName);
|
||||||
|
item->setIcon(treeColNum::colItem, icon);
|
||||||
|
item->setText(treeColNum::colItem, folderName);
|
||||||
|
item->setText(treeColNum::colItemType, QString("treeItemType"));
|
||||||
|
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsAutoTristate);
|
||||||
|
item->setCheckState(treeColNum::colItem, Qt::Unchecked);
|
||||||
|
item->setData(treeColNum::colItem, Qt::UserRole, QVariant(dirName));
|
||||||
|
|
||||||
|
//添加子节点
|
||||||
|
if (parItem->type() == treeItemType::itemFile) { //若是文件节点
|
||||||
|
parItem->addChild(item);
|
||||||
|
} else if (parItem->type() == treeItemType::itemRoot) { //若是唯一root节点
|
||||||
|
QTreeWidgetItem *root = ui->treeFiles->topLevelItem(0);
|
||||||
|
root->addChild(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加图片节点
|
||||||
|
void ExQTreeWidget::addImageItem(QTreeWidgetItem *parItem, QString fileName)
|
||||||
|
{
|
||||||
|
if (parItem == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QIcon icon;
|
||||||
|
icon.addFile(":/image/Image014.jpg");
|
||||||
|
|
||||||
|
//添加一个新的节点
|
||||||
|
QTreeWidgetItem* item = new QTreeWidgetItem(treeItemType::itemImage);
|
||||||
|
QString folderName = getFinalFolderName(fileName);
|
||||||
|
item->setIcon(treeColNum::colItem, icon);
|
||||||
|
item->setText(treeColNum::colItem, folderName);
|
||||||
|
item->setText(treeColNum::colItemType, QString("treeItemType"));
|
||||||
|
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsAutoTristate);
|
||||||
|
item->setCheckState(treeColNum::colItem, Qt::Unchecked);
|
||||||
|
item->setData(treeColNum::colItem, Qt::UserRole, QVariant(fileName));
|
||||||
|
|
||||||
|
//添加子节点
|
||||||
|
if (parItem->type() == treeItemType::itemFile) { //若是文件节点
|
||||||
|
parItem->addChild(item);
|
||||||
|
} else if (parItem->type() == treeItemType::itemRoot) { //若是唯一root节点
|
||||||
|
QTreeWidgetItem *root = ui->treeFiles->topLevelItem(0);
|
||||||
|
root->addChild(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//从完整的路径里面,获取最后的文件夹名称
|
||||||
|
QString ExQTreeWidget::getFinalFolderName(const QString &pathName)
|
||||||
|
{
|
||||||
|
QString path = pathName;
|
||||||
|
int cnt = pathName.count();
|
||||||
|
int i = pathName.lastIndexOf("/");
|
||||||
|
QString str = pathName.right(cnt - i - 1);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
//遍历传进来的父节点下的所有子节点;每遍历过该节点,就在其节点的信息加一个#
|
||||||
|
void ExQTreeWidget::changeItemCaption(QTreeWidgetItem *parItem)
|
||||||
|
{
|
||||||
|
QString str = "# " + parItem->text(treeColNum::colItem);
|
||||||
|
parItem->setText(treeColNum::colItem, str);
|
||||||
|
|
||||||
|
if (parItem->childCount() < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int i = 0; i < parItem->childCount(); i++) {
|
||||||
|
changeItemCaption(parItem->child(i)); //回调,调用自己
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//显示当前item的图片(默认以适配高度)
|
||||||
|
void ExQTreeWidget::displayImage(QTreeWidgetItem *item)
|
||||||
|
{
|
||||||
|
QString fileName = item->data(treeColNum::colItem, Qt::UserRole).toString();
|
||||||
|
m_labFlie->setText(fileName);
|
||||||
|
m_curPixmap.load(fileName); //从文件载入图片
|
||||||
|
on_actAdaptiveHeight_triggered(); //自动适应高度显示
|
||||||
|
|
||||||
|
ui->actAmplification->setEnabled(true);
|
||||||
|
ui->actShrink->setEnabled(true);
|
||||||
|
ui->actZoomRealSize->setEnabled(true);
|
||||||
|
ui->actAdaptiveHeight->setEnabled(true);
|
||||||
|
ui->actAdaptiveWidth->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
//增加文件夹
|
||||||
|
void ExQTreeWidget::on_actAddFolder_triggered()
|
||||||
|
{
|
||||||
|
QString path = QFileDialog::getExistingDirectory(); //选择目录
|
||||||
|
|
||||||
|
if (! path.isEmpty()) {
|
||||||
|
QTreeWidgetItem* item = ui->treeFiles->currentItem(); //获取当前节点
|
||||||
|
|
||||||
|
if(item != nullptr)
|
||||||
|
addFolderItem(item, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加图片
|
||||||
|
void ExQTreeWidget::on_actAddFile_triggered()
|
||||||
|
{
|
||||||
|
QStringList list = QFileDialog::getOpenFileNames(this, "选择多个将要加载的图片", "", "Images(*.jpg, *.png, *.*)"); //选择目录
|
||||||
|
|
||||||
|
if (! list.isEmpty()) {
|
||||||
|
QTreeWidgetItem* parItem = nullptr;
|
||||||
|
QTreeWidgetItem* item = ui->treeFiles->currentItem(); //获取当前节点
|
||||||
|
|
||||||
|
if (item == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (item->type() == treeItemType::itemImage) { //获得父节点
|
||||||
|
parItem = item->parent();
|
||||||
|
} else {
|
||||||
|
parItem = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
QString strName = list.at(i); //获得文件名称
|
||||||
|
addImageItem(parItem, strName); //添加图片文件到文件节点
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除节点
|
||||||
|
void ExQTreeWidget::on_actDeleFile_triggered()
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* parItem = nullptr;
|
||||||
|
QTreeWidgetItem* currItem = ui->treeFiles->currentItem();
|
||||||
|
|
||||||
|
if (currItem->type() != treeItemType::itemRoot)
|
||||||
|
parItem = currItem->parent(); //只能够由其父节点删除
|
||||||
|
// else
|
||||||
|
// ui->treeFiles->takeTopLevelItem(0); //删除顶层节点使用这个
|
||||||
|
|
||||||
|
if (currItem == nullptr || parItem == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
parItem->removeChild(currItem); //移除没有从内存中删除,所以delete删除
|
||||||
|
delete currItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
//遍历所有的顶层节点(本处只有一个root顶层节点)
|
||||||
|
void ExQTreeWidget::on_actScanItems_triggered()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < ui->treeFiles->topLevelItemCount(); i++) {
|
||||||
|
QTreeWidgetItem* currItem = ui->treeFiles->topLevelItem(i); //顶层item
|
||||||
|
changeItemCaption(currItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//图片自动适应高度
|
||||||
|
void ExQTreeWidget::on_actAdaptiveHeight_triggered()
|
||||||
|
{
|
||||||
|
int height = ui->scrollArea->height(); //得到scrollArea的高度
|
||||||
|
int realHeight = m_curPixmap.height(); //原始图片的实际高度
|
||||||
|
m_ratio = height * 1.0 / realHeight; //当前显示比例,必须转换为浮点数
|
||||||
|
|
||||||
|
QPixmap pixmap = m_curPixmap.scaledToHeight(height - 50); //图片缩放到指定高度
|
||||||
|
ui->labDisplay->setPixmap(pixmap); //设置Label的PixMap
|
||||||
|
}
|
||||||
|
|
||||||
|
//图片自动适应宽度
|
||||||
|
void ExQTreeWidget::on_actAdaptiveWidth_triggered()
|
||||||
|
{
|
||||||
|
int width = ui->scrollArea->width();
|
||||||
|
int realWidth = m_curPixmap.width();
|
||||||
|
m_ratio = width * 1.0 / realWidth;
|
||||||
|
|
||||||
|
QPixmap pixmap = m_curPixmap.scaledToHeight(width - 50);
|
||||||
|
ui->labDisplay->setPixmap(pixmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
//当前节点变化的时候,自动加载当前图片
|
||||||
|
void ExQTreeWidget::on_treeFiles_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
|
||||||
|
{
|
||||||
|
if (current != nullptr && previous != nullptr) {
|
||||||
|
displayImage(current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//放大
|
||||||
|
void ExQTreeWidget::on_actAmplification_triggered()
|
||||||
|
{
|
||||||
|
m_ratio *= 1.2; //在当前比例基础上乘以0.8
|
||||||
|
int height = m_curPixmap.height() * m_ratio; // 显示宽度
|
||||||
|
int widht = m_curPixmap.width() * m_ratio; // 显示宽度
|
||||||
|
|
||||||
|
QPixmap pix = m_curPixmap.scaled(widht, height); //图片缩放到指定高度和宽度,保持长宽比例
|
||||||
|
ui->labDisplay->setPixmap(pix);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//缩小
|
||||||
|
void ExQTreeWidget::on_actShrink_triggered()
|
||||||
|
{
|
||||||
|
m_ratio *= 0.8;
|
||||||
|
int height = m_curPixmap.height() * m_ratio;
|
||||||
|
int widht = m_curPixmap.width() * m_ratio;
|
||||||
|
|
||||||
|
QPixmap pix = m_curPixmap.scaled(widht, height);
|
||||||
|
ui->labDisplay->setPixmap(pix);
|
||||||
|
}
|
||||||
|
|
||||||
|
//还原
|
||||||
|
void ExQTreeWidget::on_actZoomRealSize_triggered()
|
||||||
|
{
|
||||||
|
m_ratio = 1;
|
||||||
|
int height = m_curPixmap.height();
|
||||||
|
int widht = m_curPixmap.width();
|
||||||
|
|
||||||
|
QPixmap pix = m_curPixmap.scaled(widht, height);
|
||||||
|
ui->labDisplay->setPixmap(pix);
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置Dock窗口是否浮动
|
||||||
|
void ExQTreeWidget::on_actDockFloating_triggered(bool check)
|
||||||
|
{
|
||||||
|
ui->dockWidget->setFloating(check);
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置Dock窗口是否隐藏不显示
|
||||||
|
void ExQTreeWidget::on_actDockVisible_triggered(bool checked)
|
||||||
|
{
|
||||||
|
ui->dockWidget->setVisible(!checked);
|
||||||
|
}
|
||||||
|
|
||||||
|
//退出
|
||||||
|
void ExQTreeWidget::on_actQiut_triggered()
|
||||||
|
{
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
//单击DockWidget组件的标题栏的关闭按钮时候,会隐藏在停靠区域,并且发射信号visibilityChanged; 停靠区域可见性变化
|
||||||
|
void ExQTreeWidget::on_dockWidget_visibilityChanged(bool visible)
|
||||||
|
{
|
||||||
|
ui->actDockVisible->setChecked(visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
//当拖动DockWidget组件,使其浮动或者停靠时候,会发射信号topLevelChanged; 更新其Action的状态
|
||||||
|
void ExQTreeWidget::on_dockWidget_topLevelChanged(bool topLevel)
|
||||||
|
{
|
||||||
|
ui->actDockFloating->setChecked(topLevel);
|
||||||
|
}
|
66
QtQTreeWidgetEx/ExQTreeWidget.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#ifndef EXQTREEWIDGET_H
|
||||||
|
#define EXQTREEWIDGET_H
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QTreeWidgetItem>
|
||||||
|
#include <QFileDialog>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class ExQTreeWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExQTreeWidget : public QMainWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum treeItemType { //枚举,节点类型
|
||||||
|
itemRoot,
|
||||||
|
itemFile,
|
||||||
|
itemImage
|
||||||
|
};
|
||||||
|
|
||||||
|
enum treeColNum { //目录树列表的编号
|
||||||
|
colItem = 0,
|
||||||
|
colItemType = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit ExQTreeWidget(QWidget *parent = nullptr);
|
||||||
|
~ExQTreeWidget();
|
||||||
|
|
||||||
|
void initTree(); //初始化根节点(唯一)
|
||||||
|
void addFolderItem(QTreeWidgetItem *parItem, QString dirName); //添加目录
|
||||||
|
void addImageItem(QTreeWidgetItem *parItem, QString fileName); //添加图片文件
|
||||||
|
QString getFinalFolderName(const QString &pathName); //从完整的路径里面,获取最后的文件夹名称
|
||||||
|
void changeItemCaption(QTreeWidgetItem* parItem); //遍历item下面的所有节点
|
||||||
|
void displayImage(QTreeWidgetItem* item); //显示当前item的图片(默认以适配高度)
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_actAddFolder_triggered(); //增加文件夹
|
||||||
|
void on_actAddFile_triggered(); //添加图片文件
|
||||||
|
void on_actDeleFile_triggered(); //删除节点
|
||||||
|
void on_actScanItems_triggered(); //遍历所有的顶层节点(本处只有一个root顶层节点)
|
||||||
|
void on_actAdaptiveHeight_triggered(); //图片自动适应高度
|
||||||
|
void on_actAdaptiveWidth_triggered(); //图片自动适应宽度
|
||||||
|
void on_actAmplification_triggered(); //放大
|
||||||
|
void on_actShrink_triggered(); //缩小
|
||||||
|
void on_actZoomRealSize_triggered(); //还原
|
||||||
|
void on_actDockFloating_triggered(bool check); //设置Dock窗口是否浮动
|
||||||
|
void on_actDockVisible_triggered(bool checked); //设置Dock窗口是否隐藏不显示
|
||||||
|
void on_actQiut_triggered(); //退出
|
||||||
|
void on_treeFiles_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); //当前节点变化的时候,自动加载当前图片
|
||||||
|
void on_dockWidget_visibilityChanged(bool visible); //单击DockWidget组件的标题栏的关闭按钮时候,会隐藏在停靠区域,并且发射信号visibilityChanged; 停靠区域可见性变化
|
||||||
|
void on_dockWidget_topLevelChanged(bool topLevel); //当拖动DockWidget组件,使其浮动或者停靠时候,会发射信号topLevelChanged; 更新其Action的状态
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::ExQTreeWidget *ui;
|
||||||
|
|
||||||
|
QLabel *m_labFlie; //状态栏显示当前文件路径
|
||||||
|
QPixmap m_curPixmap; //显示当前文件图片
|
||||||
|
float m_ratio; //图片缩放比例
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EXQTREEWIDGET_H
|
305
QtQTreeWidgetEx/ExQTreeWidget.ui
Normal file
@ -0,0 +1,305 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ExQTreeWidget</class>
|
||||||
|
<widget class="QMainWindow" name="ExQTreeWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>851</width>
|
||||||
|
<height>564</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>ExQTreeWidget</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralWidget">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QScrollArea" name="scrollArea">
|
||||||
|
<property name="widgetResizable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>556</width>
|
||||||
|
<height>449</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labDisplay">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menuBar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>851</width>
|
||||||
|
<height>23</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<widget class="QMenu" name="menu">
|
||||||
|
<property name="title">
|
||||||
|
<string>文件</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actAddFolder"/>
|
||||||
|
<addaction name="actAddFile"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actDeleFile"/>
|
||||||
|
<addaction name="actScanItems"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menu_2">
|
||||||
|
<property name="title">
|
||||||
|
<string>视图</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actAmplification"/>
|
||||||
|
<addaction name="actShrink"/>
|
||||||
|
<addaction name="actZoomRealSize"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actAdaptiveHeight"/>
|
||||||
|
<addaction name="actAdaptiveWidth"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menu_3">
|
||||||
|
<property name="title">
|
||||||
|
<string>工具</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actDockFloating"/>
|
||||||
|
<addaction name="actDockVisible"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actQiut"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menu"/>
|
||||||
|
<addaction name="menu_2"/>
|
||||||
|
<addaction name="menu_3"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QToolBar" name="mainToolBar">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="toolButtonStyle">
|
||||||
|
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||||
|
</property>
|
||||||
|
<attribute name="toolBarArea">
|
||||||
|
<enum>TopToolBarArea</enum>
|
||||||
|
</attribute>
|
||||||
|
<attribute name="toolBarBreak">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
|
<addaction name="actAddFolder"/>
|
||||||
|
<addaction name="actAddFile"/>
|
||||||
|
<addaction name="actDeleFile"/>
|
||||||
|
<addaction name="actScanItems"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actAmplification"/>
|
||||||
|
<addaction name="actShrink"/>
|
||||||
|
<addaction name="actZoomRealSize"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actAdaptiveHeight"/>
|
||||||
|
<addaction name="actAdaptiveWidth"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actDockFloating"/>
|
||||||
|
<addaction name="actDockVisible"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actQiut"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusBar"/>
|
||||||
|
<widget class="QDockWidget" name="dockWidget">
|
||||||
|
<attribute name="dockWidgetArea">
|
||||||
|
<number>1</number>
|
||||||
|
</attribute>
|
||||||
|
<widget class="QWidget" name="dockWidgetContents">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeWidget" name="treeFiles">
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>节点</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>节点类型</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<action name="actAddFolder">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="resources.qrc">
|
||||||
|
<normaloff>:/image/Image016.jpg</normaloff>:/image/Image016.jpg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>添加文件夹</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>添加文件夹</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actAddFile">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="resources.qrc">
|
||||||
|
<normaloff>:/image/Image007.jpg</normaloff>:/image/Image007.jpg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>添加文件</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>添加文件</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actDeleFile">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="resources.qrc">
|
||||||
|
<normaloff>:/image/Image005.jpg</normaloff>:/image/Image005.jpg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>删除文件</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>删除文件</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Del</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actScanItems">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="resources.qrc">
|
||||||
|
<normaloff>:/image/Image008.jpg</normaloff>:/image/Image008.jpg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>遍历节点</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>遍历节点</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actAmplification">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="resources.qrc">
|
||||||
|
<normaloff>:/image/Image012.jpg</normaloff>:/image/Image012.jpg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>放大</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>放大图片</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actShrink">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="resources.qrc">
|
||||||
|
<normaloff>:/image/Image011.jpg</normaloff>:/image/Image011.jpg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>缩小</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>缩小图片</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actZoomRealSize">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="resources.qrc">
|
||||||
|
<normaloff>:/image/Image002.jpg</normaloff>:/image/Image002.jpg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>实际大小</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>还原成实际大小</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actAdaptiveHeight">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="resources.qrc">
|
||||||
|
<normaloff>:/image/Image009.jpg</normaloff>:/image/Image009.jpg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>最佳高度</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>缩放到最佳高度</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actAdaptiveWidth">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="resources.qrc">
|
||||||
|
<normaloff>:/image/Image010.jpg</normaloff>:/image/Image010.jpg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>最佳宽度</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>缩放至最佳宽度</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actDockFloating">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="resources.qrc">
|
||||||
|
<normaloff>:/image/Image015.jpg</normaloff>:/image/Image015.jpg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>窗口浮动</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>窗口浮动开关</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actDockVisible">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="resources.qrc">
|
||||||
|
<normaloff>:/image/Image003.jpg</normaloff>:/image/Image003.jpg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>隐藏</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>窗口隐藏</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actQiut">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="resources.qrc">
|
||||||
|
<normaloff>:/image/Image004.jpg</normaloff>:/image/Image004.jpg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>退出</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>退出本程序</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
</widget>
|
||||||
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
|
<resources>
|
||||||
|
<include location="resources.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
45
QtQTreeWidgetEx/QtQTreeWidgetEx.pro
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
#-------------------------------------------------
|
||||||
|
#
|
||||||
|
# Project created by QtCreator 2019-09-04T00:32:28
|
||||||
|
#
|
||||||
|
#-------------------------------------------------
|
||||||
|
|
||||||
|
QT += core gui
|
||||||
|
|
||||||
|
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||||
|
|
||||||
|
TARGET = QtQTreeWidgetEx
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
# The following define makes your compiler emit warnings if you use
|
||||||
|
# any feature of Qt which has been marked as deprecated (the exact warnings
|
||||||
|
# depend on your compiler). Please consult the documentation of the
|
||||||
|
# deprecated API in order to know how to port your code away from it.
|
||||||
|
DEFINES += QT_DEPRECATED_WARNINGS
|
||||||
|
|
||||||
|
# You can also make your code fail to compile if you use deprecated APIs.
|
||||||
|
# In order to do so, uncomment the following line.
|
||||||
|
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||||
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||||
|
|
||||||
|
CONFIG += c++11
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
main.cpp \
|
||||||
|
ExQTreeWidget.cpp
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
ExQTreeWidget.h
|
||||||
|
|
||||||
|
FORMS += \
|
||||||
|
ExQTreeWidget.ui
|
||||||
|
|
||||||
|
RC_ICONS += qt.ico
|
||||||
|
|
||||||
|
# Default rules for deployment.
|
||||||
|
qnx: target.path = /tmp/$${TARGET}/bin
|
||||||
|
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||||
|
!isEmpty(target.path): INSTALLS += target
|
||||||
|
|
||||||
|
RESOURCES += \
|
||||||
|
resources.qrc
|
BIN
QtQTreeWidgetEx/image/Image001.jpg
Normal file
After Width: | Height: | Size: 669 B |
BIN
QtQTreeWidgetEx/image/Image002.jpg
Normal file
After Width: | Height: | Size: 877 B |
BIN
QtQTreeWidgetEx/image/Image003.jpg
Normal file
After Width: | Height: | Size: 953 B |
BIN
QtQTreeWidgetEx/image/Image004.jpg
Normal file
After Width: | Height: | Size: 957 B |
BIN
QtQTreeWidgetEx/image/Image005.jpg
Normal file
After Width: | Height: | Size: 592 B |
BIN
QtQTreeWidgetEx/image/Image006.jpg
Normal file
After Width: | Height: | Size: 866 B |
BIN
QtQTreeWidgetEx/image/Image007.jpg
Normal file
After Width: | Height: | Size: 827 B |
BIN
QtQTreeWidgetEx/image/Image008.jpg
Normal file
After Width: | Height: | Size: 1009 B |
BIN
QtQTreeWidgetEx/image/Image009.jpg
Normal file
After Width: | Height: | Size: 776 B |
BIN
QtQTreeWidgetEx/image/Image010.jpg
Normal file
After Width: | Height: | Size: 778 B |
BIN
QtQTreeWidgetEx/image/Image011.jpg
Normal file
After Width: | Height: | Size: 943 B |
BIN
QtQTreeWidgetEx/image/Image012.jpg
Normal file
After Width: | Height: | Size: 949 B |
BIN
QtQTreeWidgetEx/image/Image013.ico
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
QtQTreeWidgetEx/image/Image014.jpg
Normal file
After Width: | Height: | Size: 792 B |
BIN
QtQTreeWidgetEx/image/Image015.jpg
Normal file
After Width: | Height: | Size: 729 B |
BIN
QtQTreeWidgetEx/image/Image016.jpg
Normal file
After Width: | Height: | Size: 607 B |
11
QtQTreeWidgetEx/main.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "ExQTreeWidget.h"
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
ExQTreeWidget w;
|
||||||
|
w.show();
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
}
|
BIN
QtQTreeWidgetEx/qt.ico
Normal file
After Width: | Height: | Size: 4.2 KiB |
20
QtQTreeWidgetEx/resources.qrc
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>image/Image001.jpg</file>
|
||||||
|
<file>image/Image002.jpg</file>
|
||||||
|
<file>image/Image003.jpg</file>
|
||||||
|
<file>image/Image004.jpg</file>
|
||||||
|
<file>image/Image005.jpg</file>
|
||||||
|
<file>image/Image006.jpg</file>
|
||||||
|
<file>image/Image007.jpg</file>
|
||||||
|
<file>image/Image008.jpg</file>
|
||||||
|
<file>image/Image009.jpg</file>
|
||||||
|
<file>image/Image010.jpg</file>
|
||||||
|
<file>image/Image011.jpg</file>
|
||||||
|
<file>image/Image012.jpg</file>
|
||||||
|
<file>image/Image013.ico</file>
|
||||||
|
<file>image/Image014.jpg</file>
|
||||||
|
<file>image/Image015.jpg</file>
|
||||||
|
<file>image/Image016.jpg</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
@ -34,7 +34,7 @@ HEADERS += \
|
|||||||
FORMS += \
|
FORMS += \
|
||||||
ExQListWidget.ui
|
ExQListWidget.ui
|
||||||
|
|
||||||
RC_ICONS += qt.ico
|
#RC_ICONS += qt.ico
|
||||||
|
|
||||||
# Default rules for deployment.
|
# Default rules for deployment.
|
||||||
qnx: target.path = /tmp/$${TARGET}/bin
|
qnx: target.path = /tmp/$${TARGET}/bin
|
||||||
|
@ -68,6 +68,8 @@
|
|||||||
- 自定义`QStyle`界面所有控件的风格,换肤效果的教程,自定义继承`QCommonStyle`的风格类【QtCustomStyleEx】
|
- 自定义`QStyle`界面所有控件的风格,换肤效果的教程,自定义继承`QCommonStyle`的风格类【QtCustomStyleEx】
|
||||||
- 预备知识:`QStyle`、`QCommonStyle`d等讲解
|
- 预备知识:`QStyle`、`QCommonStyle`d等讲解
|
||||||
- [更换`Qt`应用程序的界面`UI`,实现换肤,改用自带其他默认`QStyle`风格样式](https://mp.csdn.net/mdeditor/100148539#)
|
- [更换`Qt`应用程序的界面`UI`,实现换肤,改用自带其他默认`QStyle`风格样式](https://mp.csdn.net/mdeditor/100148539#)
|
||||||
|
- [`QStyle`自定义重绘`QSlider`控件](https://blog.csdn.net/qq_33154343/article/details/100545769)
|
||||||
|
- [QStyle自定义重绘QRubberBand控件](https://blog.csdn.net/qq_33154343/article/details/100588428)
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|