提交 36f2e0c6 编写于 作者: mahuifa's avatar mahuifa

新功能:实现QssDemo功能

    1、实现QHeaderView标题行样式;
    2、实现QTreeView、QTreeWidget示例。
上级 29f8634a
......@@ -4,6 +4,7 @@
#include <QDebug>
#include <QToolBar>
#include <QStyle>
#include <QFileSystemModel>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
......@@ -14,6 +15,7 @@ MainWindow::MainWindow(QWidget *parent)
this->setWindowTitle("Qss样式表常见用法Demo");
init();
initListView();
initTreeView();
initStyle();
connectSlots();
}
......@@ -78,7 +80,17 @@ void MainWindow::initListView()
ui->listView_2->setModel(strModel);
ui->undoView->setModel(strModel);
ui->listWidget->addItems(strList);
}
/**
* @brief 初始化QTreeView
*/
void MainWindow::initTreeView()
{
QFileSystemModel* model = new QFileSystemModel; // 提供对本地文件系统的访问
model->setRootPath(QDir::currentPath()); // 将模型正在监视的目录设置为newPath
ui->treeView->setModel(model);
ui->treeView_2->setModel(model);
}
/**
......@@ -112,6 +124,8 @@ void MainWindow::connectSlots()
connect(ui->horizontalSlider, &QSlider::valueChanged, ui->progressBar, &QProgressBar::setValue);
connect(ui->horizontalSlider_2, &QSlider::valueChanged, ui->progressBar_2, &QProgressBar::setValue);
connect(ui->verticalSlider, &QSlider::valueChanged, ui->progressBar_3, &QProgressBar::setValue);
connect(ui->treeView, &QTreeView::expanded, ui->treeView_2, &QTreeView::setRootIndex); // 可以通过设置树视图的根索引来显示特定目录的内容
}
/**
......
......@@ -24,6 +24,7 @@ private slots:
private:
void init();
void initListView();
void initTreeView();
void initStyle();
void connectSlots();
......
......@@ -21,7 +21,7 @@
<string notr="true"/>
</property>
<property name="currentIndex">
<number>6</number>
<number>7</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
......@@ -1707,7 +1707,7 @@ p, li { white-space: pre-wrap; }
</widget>
<widget class="QWidget" name="tab_16">
<attribute name="title">
<string>常用组件</string>
<string>QListView</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
......@@ -1745,8 +1745,114 @@ p, li { white-space: pre-wrap; }
</widget>
<widget class="QWidget" name="tab_17">
<attribute name="title">
<string>常用组件</string>
<string>QTreeView</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_16">
<item row="0" column="0">
<widget class="QTreeView" name="treeView"/>
</item>
<item row="0" column="1">
<widget class="QTreeView" name="treeView_2">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::NoDragDrop</enum>
</property>
<property name="alternatingRowColors">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QTreeWidget" name="treeWidget_2">
<property name="styleSheet">
<string notr="true"/>
</property>
<column>
<property name="text">
<string>第一列</string>
</property>
</column>
<column>
<property name="text">
<string>第二列</string>
</property>
</column>
<column>
<property name="text">
<string>第三列</string>
</property>
</column>
<item>
<property name="text">
<string>新建项目</string>
</property>
<property name="text">
<string>123</string>
</property>
<property name="text">
<string>321</string>
</property>
<item>
<property name="text">
<string>新建子项目</string>
</property>
<property name="text">
<string>123</string>
</property>
<property name="text">
<string>321</string>
</property>
</item>
</item>
<item>
<property name="text">
<string>新建项目</string>
</property>
<property name="text">
<string>123</string>
</property>
<property name="text">
<string>321</string>
</property>
<item>
<property name="text">
<string>新建子项目</string>
</property>
<property name="text">
<string>123</string>
</property>
<property name="text">
<string>321</string>
</property>
</item>
</item>
<item>
<property name="text">
<string>新建项目</string>
</property>
<property name="text">
<string>123</string>
</property>
<property name="text">
<string>321</string>
</property>
<item>
<property name="text">
<string>新建子项目</string>
</property>
<property name="text">
<string>123</string>
</property>
<property name="text">
<string>321</string>
</property>
</item>
</item>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
......
......@@ -887,3 +887,19 @@ QListView::item:hover { /* 鼠标进入行的样式*/
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #FFABFE, stop: 1 #DCDEF1);
}
/********************QHeaderView标题行样式**********************/
QHeaderView::section { /*标题行样式*/
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #FFABFE, stop: 1 #DCDEF1);
color: white; /* 设置标题行字体颜色*/
padding-left: 10px; /* 设置元素左内边距*/
border: 1px solid #6c6c6c;
}
/* 没有具体效果,不知道是怎么用的,后面有时间在研究*/
QHeaderView::section:checked,
QHeaderView::down-arrow,
QHeaderView::up-arrow {
background-color: red;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册