├── .gitignore ├── FramelessWindow ├── CustomModelView │ ├── customheaderview.cpp │ ├── customheaderview.h │ ├── customheaderview.ui │ ├── customhorizontalheaderview.cpp │ ├── customhorizontalheaderview.h │ ├── customlineeditedelegate.cpp │ ├── customlineeditedelegate.h │ ├── customlistview.cpp │ ├── customlistview.h │ ├── custommodel.cpp │ ├── custommodel.h │ ├── customtableview.cpp │ ├── customtableview.h │ ├── customtreeview.cpp │ └── customtreeview.h ├── FrameLessWidget │ ├── framelesswidget.cpp │ ├── framelesswidget.h │ ├── framelesswidget.ui │ ├── images.qrc │ └── images │ │ ├── 6.png │ │ ├── caret-left.png │ │ ├── caret-right.png │ │ ├── checkbox--checked.png │ │ ├── checkbox.png │ │ ├── checkbox_dis.png │ │ ├── filter.png │ │ ├── fullscreen.png │ │ ├── fullscreen_exit.png │ │ ├── icon.png │ │ ├── icon_window_close.png │ │ ├── icon_window_maximize.png │ │ ├── icon_window_minimize.png │ │ ├── icon_window_restore.png │ │ ├── qt_zh_CN.qm │ │ ├── radio-button--checked.png │ │ ├── radio-button.png │ │ ├── radio-button_dis.png │ │ ├── sort_down.png │ │ ├── sort_up.png │ │ ├── window.ico │ │ ├── window.rc │ │ └── 界面20200103.jpg ├── FramelessWindow.pro ├── basicwidget.cpp ├── basicwidget.h ├── basicwidget.ui ├── darkstyle │ ├── darkstyle.qss │ ├── icon_branch_closed.png │ ├── icon_branch_end.png │ ├── icon_branch_more.png │ ├── icon_branch_open.png │ ├── icon_checkbox_checked.png │ ├── icon_checkbox_checked_disabled.png │ ├── icon_checkbox_checked_pressed.png │ ├── icon_checkbox_indeterminate.png │ ├── icon_checkbox_indeterminate_disabled.png │ ├── icon_checkbox_indeterminate_pressed.png │ ├── icon_checkbox_unchecked.png │ ├── icon_checkbox_unchecked_disabled.png │ ├── icon_checkbox_unchecked_pressed.png │ ├── icon_close.png │ ├── icon_radiobutton_checked.png │ ├── icon_radiobutton_checked_disabled.png │ ├── icon_radiobutton_checked_pressed.png │ ├── icon_radiobutton_unchecked.png │ ├── icon_radiobutton_unchecked_disabled.png │ ├── icon_radiobutton_unchecked_pressed.png │ ├── icon_restore.png │ ├── icon_undock.png │ └── icon_vline.png ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h └── mainwindow.ui ├── LICENSE ├── README.md ├── Untitled Diagram.drawio └── doc ├── chart.gif └── home.png /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | *.slo 3 | *.lo 4 | *.o 5 | *.a 6 | *.la 7 | *.lai 8 | *.so 9 | *.so.* 10 | *.dll 11 | *.dylib 12 | 13 | # Qt-es 14 | object_script.*.Release 15 | object_script.*.Debug 16 | *_plugin_import.cpp 17 | /.qmake.cache 18 | /.qmake.stash 19 | *.pro.user 20 | *.pro.user.* 21 | *.qbs.user 22 | *.qbs.user.* 23 | *.moc 24 | moc_*.cpp 25 | moc_*.h 26 | qrc_*.cpp 27 | ui_*.h 28 | *.qmlc 29 | *.jsc 30 | Makefile* 31 | *build-* 32 | *.qm 33 | *.prl 34 | 35 | # Qt unit tests 36 | target_wrapper.* 37 | 38 | # QtCreator 39 | *.autosave 40 | 41 | # QtCreator Qml 42 | *.qmlproject.user 43 | *.qmlproject.user.* 44 | 45 | # QtCreator CMake 46 | CMakeLists.txt.user* 47 | 48 | # QtCreator 4.8< compilation database 49 | compile_commands.json 50 | 51 | # QtCreator local machine specific files for imported projects 52 | *creator.user* 53 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/customheaderview.cpp: -------------------------------------------------------------------------------- 1 | #include "customheaderview.h" 2 | #include "ui_customheaderview.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | FilterDialog::FilterDialog(QWidget *parent) : QWidget(parent) 10 | { 11 | this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint); 12 | auto hLayout = new QHBoxLayout(); 13 | m_pLineEdit = new QLineEdit(); 14 | m_pBtn = new QPushButton(); 15 | m_pBtn->setText(tr("确定")); 16 | hLayout->addWidget(m_pLineEdit); 17 | hLayout->addWidget(m_pBtn); 18 | this->setLayout(hLayout); 19 | this->setWindowModality(Qt::ApplicationModal); 20 | connect(m_pBtn, &QPushButton::clicked, this, [this](){ 21 | emit filter(this->filterMsg()); 22 | this->close(); 23 | }); 24 | } 25 | 26 | 27 | CustomHeaderView::CustomHeaderView(int index, QWidget *parent) : 28 | QWidget(parent), 29 | ui(new Ui::CustomHeaderView), 30 | m_index(index), 31 | m_pFilterDialog(new FilterDialog) 32 | { 33 | ui->setupUi(this); 34 | ui->toolButton_filter->setVisible(false); 35 | ui->toolButton_sortUp->setVisible(false); 36 | ui->toolButton_sortDown->setVisible(false); 37 | this->setObjectName("CustomHeaderView"); 38 | m_pFilterDialog->hide(); 39 | connect(ui->toolButton_sortUp, &QToolButton::clicked, this, [this](){ 40 | ui->buttonGroup->setExclusive(true); 41 | ui->toolButton_filter->setChecked(false); 42 | ui->toolButton_sortUp->setChecked(true); 43 | ui->toolButton_sortDown->setChecked(false); 44 | this->sortedUp(m_index); 45 | }); 46 | connect(ui->toolButton_sortDown, &QToolButton::clicked, this, [this](){ 47 | ui->buttonGroup->setExclusive(true); 48 | ui->toolButton_filter->setChecked(false); 49 | ui->toolButton_sortUp->setChecked(false); 50 | ui->toolButton_sortDown->setChecked(true); 51 | this->sortedDown(m_index); 52 | }); 53 | 54 | connect(ui->toolButton_filter, &QToolButton::clicked, this, [this](){ 55 | ui->buttonGroup->setExclusive(true); 56 | ui->toolButton_filter->setChecked(true); 57 | ui->toolButton_sortUp->setChecked(false); 58 | ui->toolButton_sortDown->setChecked(false); 59 | auto zero = this->mapToGlobal(QPoint(ui->label_title->pos().x(), ui->label_title->pos().y())); 60 | m_pFilterDialog->move(zero.x(), zero.y() + this->height()); 61 | m_pFilterDialog->resize(this->size() + QSize(5, 0)); 62 | m_pFilterDialog->show(); 63 | }); 64 | connect(m_pFilterDialog, &FilterDialog::filter, this, [this](QString msg){ 65 | this->filter(m_index, msg); 66 | }); 67 | ui->widget_header->installEventFilter(this); 68 | ui->label_title->installEventFilter(this); 69 | ui->toolButton_filter->installEventFilter(this); 70 | ui->toolButton_sortUp->installEventFilter(this); 71 | ui->toolButton_sortDown->installEventFilter(this); 72 | } 73 | 74 | CustomHeaderView::~CustomHeaderView() 75 | { 76 | delete ui; 77 | if(m_pFilterDialog != nullptr){ 78 | delete m_pFilterDialog; 79 | m_pFilterDialog = nullptr; 80 | } 81 | } 82 | 83 | void CustomHeaderView::setTitle(QString text) 84 | { 85 | ui->label_title->setText(text); 86 | } 87 | QString CustomHeaderView::title() 88 | { 89 | return ui->label_title->text(); 90 | } 91 | 92 | void CustomHeaderView::setAlignment(Qt::Alignment align) 93 | { 94 | ui->label_title->setAlignment(align); 95 | } 96 | 97 | void CustomHeaderView::sortUpVisible(bool status) 98 | { 99 | ui->toolButton_sortUp->setVisible(status); 100 | } 101 | 102 | void CustomHeaderView::sortDownVisible(bool status) 103 | { 104 | ui->toolButton_sortDown->setVisible(status); 105 | } 106 | 107 | void CustomHeaderView::filterVisible(bool status) 108 | { 109 | ui->toolButton_filter->setVisible(status); 110 | } 111 | 112 | void CustomHeaderView::clearStatus() 113 | { 114 | ui->buttonGroup->setExclusive(false); 115 | ui->toolButton_filter->setChecked(false); 116 | ui->toolButton_sortUp->setChecked(false); 117 | ui->toolButton_sortDown->setChecked(false); 118 | } 119 | void CustomHeaderView::clearFilterStatus() 120 | { 121 | ui->buttonGroup->setExclusive(false); 122 | ui->toolButton_filter->setChecked(false); 123 | } 124 | 125 | QString CustomHeaderView::getFilterMsg() 126 | { 127 | return m_pFilterDialog->filterMsg(); 128 | } 129 | 130 | bool CustomHeaderView::eventFilter(QObject *obj, QEvent *event) 131 | { 132 | if(obj == ui->widget_header || obj == ui->label_title || obj == ui->toolButton_filter 133 | || obj == ui->toolButton_sortUp || obj == ui->toolButton_sortDown){ 134 | setCursor(Qt::ArrowCursor); 135 | } 136 | if(event->type() == QEvent::Leave && obj == ui->widget_header){ 137 | qDebug() << "Leave, header object name: " << obj->objectName(); 138 | ui->toolButton_filter->setVisible(false); 139 | ui->toolButton_sortUp->setVisible(false); 140 | ui->toolButton_sortDown->setVisible(false); 141 | }else if(event->type() == QEvent::Enter && obj == ui->widget_header){ 142 | qDebug() << "Enter, header object name: " << obj->objectName(); 143 | ui->toolButton_filter->setVisible(true); 144 | ui->toolButton_sortUp->setVisible(true); 145 | ui->toolButton_sortDown->setVisible(true); 146 | } 147 | return QWidget::eventFilter(obj, event); 148 | } 149 | 150 | 151 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/customheaderview.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMHEADERVIEW_H 2 | #define CUSTOMHEADERVIEW_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Ui { 9 | class CustomHeaderView; 10 | } 11 | 12 | class FilterDialog; 13 | 14 | /* 15 | * 自定义横向表头内容框 16 | */ 17 | class CustomHeaderView : public QWidget 18 | { 19 | Q_OBJECT 20 | 21 | public: 22 | explicit CustomHeaderView(int index, QWidget *parent = nullptr); 23 | ~CustomHeaderView(); 24 | 25 | void setTitle(QString text); 26 | QString title(); 27 | void setAlignment(Qt::Alignment align); 28 | void sortUpVisible(bool status); 29 | void sortDownVisible(bool status); 30 | void filterVisible(bool status); 31 | void clearStatus(); 32 | void clearFilterStatus(); 33 | QString getFilterMsg(); 34 | 35 | signals: 36 | void sortedUp(int index); 37 | void sortedDown(int index); 38 | void filter(int index, QString msg); 39 | 40 | protected: 41 | virtual bool eventFilter(QObject *obj, QEvent *event); 42 | 43 | private: 44 | Ui::CustomHeaderView *ui; 45 | // 索引 46 | int m_index = 0; 47 | 48 | FilterDialog *m_pFilterDialog; 49 | }; 50 | 51 | class FilterDialog : public QWidget 52 | { 53 | Q_OBJECT 54 | 55 | public: 56 | FilterDialog(QWidget *parent = nullptr); 57 | QString filterMsg(){ 58 | return this->m_pLineEdit->text().trimmed(); 59 | } 60 | signals: 61 | void filter(QString msg); 62 | 63 | private: 64 | QPushButton *m_pBtn; 65 | QLineEdit *m_pLineEdit; 66 | }; 67 | 68 | #endif // CUSTOMHEADERVIEW_H 69 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/customheaderview.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | CustomHeaderView 4 | 5 | 6 | 7 | 0 8 | 0 9 | 80 10 | 32 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | false 18 | 19 | 20 | 21 | 22 | 23 | 24 | 0 25 | 26 | 27 | 0 28 | 29 | 30 | 0 31 | 32 | 33 | 0 34 | 35 | 36 | 0 37 | 38 | 39 | 40 | 41 | false 42 | 43 | 44 | 45 | 0 46 | 47 | 48 | 0 49 | 50 | 51 | 0 52 | 53 | 54 | 0 55 | 56 | 57 | 0 58 | 59 | 60 | 61 | 62 | 0 63 | 64 | 65 | 66 | 67 | *** 68 | 69 | 70 | Qt::AlignCenter 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 0 79 | 0 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | :/images/filter.png:/images/filter.png 88 | 89 | 90 | 91 | 16 92 | 16 93 | 94 | 95 | 96 | true 97 | 98 | 99 | true 100 | 101 | 102 | false 103 | 104 | 105 | buttonGroup 106 | 107 | 108 | 109 | 110 | 111 | 112 | 0 113 | 114 | 115 | 116 | 117 | 118 | 0 119 | 0 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | :/images/sort_up.png:/images/sort_up.png 128 | 129 | 130 | 131 | 8 132 | 8 133 | 134 | 135 | 136 | true 137 | 138 | 139 | true 140 | 141 | 142 | buttonGroup 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 0 151 | 0 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | :/images/sort_down.png:/images/sort_down.png 160 | 161 | 162 | 163 | 8 164 | 8 165 | 166 | 167 | 168 | true 169 | 170 | 171 | true 172 | 173 | 174 | buttonGroup 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/customhorizontalheaderview.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "customhorizontalheaderview.h" 4 | 5 | const int HEADER_RIGHT_BORDER = 1; 6 | 7 | CustomHorizontalHeaderView::CustomHorizontalHeaderView(QWidget *parent) 8 | : QHeaderView(Qt::Horizontal, parent) 9 | { 10 | setSectionsMovable(true); 11 | setSectionsClickable(true); 12 | this->setStretchLastSection(true); 13 | this->setObjectName("CustomHorizontalHeaderView"); 14 | connect(this, &QHeaderView::sectionResized, this, &CustomHorizontalHeaderView::handleSectionResized); 15 | connect(this, &QHeaderView::sectionMoved, this, &CustomHorizontalHeaderView::handleSectionMoved); 16 | } 17 | CustomHorizontalHeaderView::~CustomHorizontalHeaderView() 18 | { 19 | for (auto tableFilter : m_pTableFilterList) { 20 | delete tableFilter; 21 | tableFilter = nullptr; 22 | } 23 | } 24 | 25 | void CustomHorizontalHeaderView::setModel(QAbstractItemModel *model) 26 | { 27 | QHeaderView::setModel(model); 28 | for (int i=0; isetTitle(this->model()->headerData(i, Qt::Horizontal).toString()); 31 | pTableFilter->show(); 32 | m_pTableFilterList.append(pTableFilter); 33 | connect(pTableFilter, &CustomHeaderView::sortedUp, this, [this](int index){ 34 | emit this->sortedUp(index); 35 | for (int i=0; iclearStatus(); 38 | } 39 | }); 40 | connect(pTableFilter, &CustomHeaderView::sortedDown, this, [this](int index){ 41 | m_pTableFilterList.at(index)->clearStatus(); 42 | emit this->sortedDown(index); 43 | for (int i=0; iclearStatus(); 46 | } 47 | }); 48 | connect(pTableFilter, &CustomHeaderView::filter, this, [this](int index, QString msg){ 49 | if(m_pTableFilterList[index]->getFilterMsg().trimmed().isEmpty()){ 50 | m_pTableFilterList[index]->clearFilterStatus(); 51 | } 52 | emit this->filter(index, msg); 53 | }); 54 | } 55 | } 56 | 57 | void CustomHorizontalHeaderView::headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast) 58 | { 59 | if(logicalFirst < 0 || logicalLast > m_pTableFilterList.length()){return;} 60 | if(orientation == Qt::Horizontal){ 61 | for (int i=logicalFirst; i<=logicalLast; ++i) { 62 | m_pTableFilterList.at(i)->setTitle(this->model()->headerData(i, Qt::Horizontal).toString()); 63 | } 64 | } 65 | } 66 | void CustomHorizontalHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const 67 | { 68 | // 屏蔽默认绘制表头,避免修改model, model 可以不更改情况下共享给不同的view 69 | // 表头内容都在showEvent中处理,目前没有其他更好方法 70 | Q_UNUSED(rect); 71 | painter->save(); 72 | QHeaderView::paintSection(painter, QRect(), logicalIndex); 73 | painter->restore(); 74 | auto pTableFilter = m_pTableFilterList.at(logicalIndex); 75 | pTableFilter->setGeometry(sectionViewportPosition(logicalIndex), 0, 76 | sectionSize(logicalIndex) - HEADER_RIGHT_BORDER, height()); 77 | pTableFilter->show(); 78 | // 根据第一个可见视图索引求出逻辑索引, 在这之前的都要隐藏 79 | int startShowIndex = this->visualIndexAt(0); 80 | for (int i=0; ihide(); 82 | } 83 | } 84 | 85 | void CustomHorizontalHeaderView::handleSectionResized(int i, int oldSize, int newSize) 86 | { 87 | Q_UNUSED(i) 88 | Q_UNUSED(oldSize); 89 | Q_UNUSED(newSize); 90 | this->fixSectionPositions(); 91 | } 92 | void CustomHorizontalHeaderView::handleSectionMoved(int logical, int oldVisualIndex, int newVisualIndex) 93 | { 94 | Q_UNUSED(logical); 95 | Q_UNUSED(oldVisualIndex); 96 | Q_UNUSED(newVisualIndex); 97 | this->fixSectionPositions(); 98 | } 99 | void CustomHorizontalHeaderView::resizeEvent(QResizeEvent *event) 100 | { 101 | QHeaderView::resizeEvent(event); 102 | this->fixSectionPositions(); 103 | } 104 | 105 | void CustomHorizontalHeaderView::fixSectionPositions() 106 | { 107 | for (int i = 0; isetGeometry(sectionViewportPosition(i), 0, 109 | sectionSize(i) - HEADER_RIGHT_BORDER, height()); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/customhorizontalheaderview.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMHORIZONTALHEADERVIEW_H 2 | #define CUSTOMHORIZONTALHEADERVIEW_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "customheaderview.h" 9 | 10 | class CustomHorizontalHeaderView : public QHeaderView 11 | { 12 | Q_OBJECT 13 | public: 14 | explicit CustomHorizontalHeaderView(QWidget *parent = nullptr); 15 | virtual ~CustomHorizontalHeaderView() override; 16 | 17 | signals: 18 | void sortedUp(int index); 19 | void sortedDown(int index); 20 | void filter(int index, QString msg); 21 | 22 | public slots: 23 | 24 | protected: 25 | void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const override; 26 | void resizeEvent(QResizeEvent *event) override; 27 | void handleSectionMoved(int logical, int oldVisualIndex, int newVisualIndex); 28 | void handleSectionResized(int i, int oldSize, int newSize); 29 | void setModel(QAbstractItemModel *model) override; 30 | void headerDataChanged(Qt::Orientation orientation, int logicalFirst, int logicalLast); 31 | void fixSectionPositions(); 32 | 33 | private: 34 | QVector m_pTableFilterList; 35 | }; 36 | 37 | #endif // CUSTOMHORIZONTALHEADERVIEW_H 38 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/customlineeditedelegate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "customlineeditedelegate.h" 3 | 4 | CustomLineEditeDelegate::CustomLineEditeDelegate(QObject *parent) : QItemDelegate(parent) 5 | { 6 | 7 | } 8 | 9 | QWidget *CustomLineEditeDelegate::createEditor(QWidget *parent, 10 | const QStyleOptionViewItem &option, 11 | const QModelIndex &index) const 12 | { 13 | return new QLineEdit(parent); 14 | } 15 | 16 | void CustomLineEditeDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const 17 | { 18 | QString value = index.model()->data(index, Qt::EditRole).toString(); 19 | auto lineEdit = static_cast(editor); 20 | lineEdit->setText(value); 21 | } 22 | void CustomLineEditeDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const 23 | { 24 | auto lineEdit = static_cast(editor); 25 | model->setData(index, lineEdit->text()); 26 | } 27 | 28 | void CustomLineEditeDelegate::updateEditorGeometry(QWidget *editor, 29 | const QStyleOptionViewItem &option, 30 | const QModelIndex &index) const 31 | { 32 | Q_UNUSED(index); 33 | editor->setGeometry(option.rect); 34 | } 35 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/customlineeditedelegate.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMLINEEDITEDELEGATE_H 2 | #define CUSTOMLINEEDITEDELEGATE_H 3 | 4 | #include 5 | #include 6 | 7 | class CustomLineEditeDelegate : public QItemDelegate 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit CustomLineEditeDelegate(QObject *parent = nullptr); 12 | QWidget *createEditor(QWidget *parent, 13 | const QStyleOptionViewItem &option, 14 | const QModelIndex &index) const override; 15 | 16 | void setEditorData(QWidget *editor, const QModelIndex &index) const override; 17 | void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; 18 | 19 | void updateEditorGeometry(QWidget *editor, 20 | const QStyleOptionViewItem &option, 21 | const QModelIndex &index) const override; 22 | 23 | signals: 24 | 25 | public slots: 26 | }; 27 | 28 | #endif // CUSTOMLINEEDITEDELEGATE_H 29 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/customlistview.cpp: -------------------------------------------------------------------------------- 1 | #include "customlistview.h" 2 | 3 | CustomListView::CustomListView(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/customlistview.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMLISTVIEW_H 2 | #define CUSTOMLISTVIEW_H 3 | 4 | #include 5 | #include 6 | 7 | class CustomListView : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit CustomListView(QObject *parent = nullptr); 12 | 13 | signals: 14 | 15 | public slots: 16 | }; 17 | 18 | #endif // CUSTOMLISTVIEW_H 19 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/custommodel.cpp: -------------------------------------------------------------------------------- 1 | #include "custommodel.h" 2 | #include 3 | #include 4 | #include 5 | 6 | CustomModel::CustomModel(QAbstractItemModel *parent) : QAbstractItemModel(parent) 7 | { 8 | // std::list intList; 9 | auto now = QDateTime::currentDateTime(); 10 | for (int i=0; i<10; ++i) { 11 | // typedef std::tuple ModeLCol; 12 | m_stocks.append({i, i*100, qrand() % 100, qrand() % 300, QString("name%1\nname_name").arg(qrand() % 100), now.addSecs(i)}); 13 | // auto item = qrand() % 100; 14 | // intList.push_back(item); 15 | // qDebug() << item; 16 | } 17 | // auto listMin = std::min_element(intList.begin(), intList.end()); 18 | // auto listMax = std::max_element(intList.begin(), intList.end()); 19 | // qDebug() << *listMin << " : " << *listMax; 20 | } 21 | 22 | int CustomModel::rowCount(const QModelIndex &parent) const 23 | { 24 | Q_UNUSED(parent); 25 | return m_stocks.length(); 26 | } 27 | int CustomModel::columnCount(const QModelIndex &parent) const 28 | { 29 | Q_UNUSED(parent); 30 | return m_names.length(); 31 | } 32 | 33 | QVariant CustomModel::data(const QModelIndex &index, int role) const 34 | { 35 | if(!index.isValid()){ 36 | qDebug() << "index is valid: " << index.row() << ":" << index.column(); 37 | return QVariant(); 38 | } 39 | if(index.row() > m_stocks.length() || index.column() > m_names.length()){ 40 | qDebug() << "m_stocks len: " << m_stocks.length() << " " << index.row() << ":" << index.column(); 41 | return QVariant(); 42 | } 43 | if(role == Qt::DisplayRole){ 44 | auto stock = m_stocks.at(index.row()); 45 | return (index.column() > stock.length() || index.column() < 0) ? QVariant() : stock.at(index.column()); 46 | } else if(role == Qt::EditRole){ 47 | auto stock = m_stocks.at(index.row()); 48 | return (index.column() > stock.length() || index.column() < 0) ? QVariant() : stock.at(index.column()); 49 | } 50 | return QVariant(); 51 | } 52 | 53 | bool CustomModel::setData(const QModelIndex &index, const QVariant &value, int role) 54 | { 55 | if(!index.isValid()){ 56 | qDebug() << "index is valid: " << index.row() << ":" << index.column(); 57 | return false; 58 | } 59 | if(role == Qt::EditRole){ 60 | auto stock = m_stocks.at(index.row()); 61 | stock[index.column()] = value; 62 | emit dataChanged(index, index); 63 | return true; 64 | } 65 | return false; 66 | } 67 | 68 | QVariant CustomModel::headerData(int section, Qt::Orientation orientation, int role) const 69 | { 70 | if(role != Qt::DisplayRole){ 71 | return QVariant(); 72 | } 73 | 74 | if(orientation == Qt::Horizontal){ 75 | if(section < 0 || section > m_names.length()){return QVariant();} 76 | return QVariant(m_names.at(section)); 77 | }else { 78 | return QVariant(QString::number(section)); 79 | } 80 | } 81 | bool CustomModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) 82 | { 83 | if(role != Qt::EditRole){ 84 | return false; 85 | } 86 | if(orientation == Qt::Horizontal){ 87 | m_names.replace(section, value.toString()); 88 | emit headerDataChanged(Qt::Horizontal, section, section); 89 | return true; 90 | }else{ 91 | return false; 92 | } 93 | } 94 | 95 | Qt::ItemFlags CustomModel::flags(const QModelIndex &index) const 96 | { 97 | if(index.isValid()){ 98 | Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemNeverHasChildren | Qt::ItemIsEditable; 99 | return flags; 100 | } 101 | return QAbstractItemModel::flags(index); 102 | } 103 | 104 | QModelIndex CustomModel::index(int row, int column, const QModelIndex &parent) const 105 | { 106 | if (row < 0 || column < 0 || column >= columnCount(parent) || column > m_names.length()) 107 | return QModelIndex(); 108 | 109 | return createIndex(row,column); 110 | } 111 | 112 | QModelIndex CustomModel::parent(const QModelIndex &child) const 113 | { 114 | Q_UNUSED(child); 115 | return QModelIndex(); 116 | } 117 | 118 | void CustomModel::sort(int column, Qt::SortOrder order) 119 | { 120 | // 修改之前发生信号 121 | emit layoutAboutToBeChanged(); 122 | if(column <= 4 && column >= 0){ 123 | if(order == Qt::AscendingOrder){ 124 | std::sort(m_stocks.begin(), m_stocks.end(), [](QVector pre, QVector item){ 125 | return pre.at(2).toInt() < item.at(2).toInt(); 126 | }); 127 | } 128 | if(order == Qt::DescendingOrder){ 129 | std::sort(m_stocks.rbegin(), m_stocks.rend(), [](QVector pre, QVector item){ 130 | return pre.at(2).toInt() < item.at(2).toInt(); 131 | }); 132 | } 133 | } 134 | // 修改之后要发送的信号 135 | emit layoutChanged(); 136 | } 137 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/custommodel.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMMODEL_H 2 | #define CUSTOMMODEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | //typedef std::tuple ModelCol; 17 | 18 | class CustomModel : public QAbstractItemModel 19 | { 20 | Q_OBJECT 21 | public: 22 | explicit CustomModel(QAbstractItemModel *parent = nullptr); 23 | 24 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; 25 | int columnCount(const QModelIndex &parent) const override; 26 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 27 | bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 28 | virtual Qt::ItemFlags flags(const QModelIndex &index) const override; 29 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; 30 | QModelIndex parent(const QModelIndex &child) const override; 31 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 32 | bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override; 33 | virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); 34 | 35 | signals: 36 | 37 | public slots: 38 | 39 | private: 40 | // 列: code, no1, no2, no3, name, datetime 41 | QVector m_names{"code", "no1", "no2", "no3", "name", "datetime"}; 42 | QList > m_stocks; 43 | }; 44 | 45 | #endif // CUSTOMMODEL_H 46 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/customtableview.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "CustomModelView/customtableview.h" 4 | 5 | 6 | CustomTableView::CustomTableView(QWidget *parent) 7 | : QTableView(parent), 8 | m_pHHeaderView(new CustomHorizontalHeaderView(this)), 9 | m_pSortFilterModel(new QSortFilterProxyModel(this)) 10 | { 11 | this->initConnect(); 12 | this->setAlternatingRowColors(true); 13 | this->setHorizontalHeader(m_pHHeaderView); 14 | this->setObjectName("CustomTableView"); 15 | } 16 | 17 | void CustomTableView::initConnect() 18 | { 19 | 20 | connect(m_pHHeaderView, &CustomHorizontalHeaderView::sortedUp, this, [this](int index){ 21 | m_pSortFilterModel->setFilterKeyColumn(index); 22 | m_pSortFilterModel->sort(index, Qt::AscendingOrder); 23 | }); 24 | connect(m_pHHeaderView, &CustomHorizontalHeaderView::sortedDown, this, [this](int index){ 25 | m_pSortFilterModel->setFilterKeyColumn(index); 26 | m_pSortFilterModel->sort(index, Qt::DescendingOrder); 27 | }); 28 | connect(m_pHHeaderView, &CustomHorizontalHeaderView::filter, this, [this](int index, QString msg){ 29 | m_pSortFilterModel->setFilterKeyColumn(index); 30 | m_pSortFilterModel->setFilterFixedString(msg); 31 | }); 32 | 33 | // 设置选中行 34 | this->setSelectionBehavior(QAbstractItemView::SelectRows); 35 | // 设置单选 36 | this->setSelectionMode(QAbstractItemView::SingleSelection); 37 | // 处理鼠标选择 38 | connect(this, &QTableView::pressed, this, [this](const QModelIndex &index){ 39 | qDebug() << "selected: " << index.row() << " data:" << this->model()->data(index).toString(); 40 | }); 41 | } 42 | 43 | void CustomTableView::setModel(QAbstractItemModel *model) 44 | { 45 | m_pSortFilterModel->setSourceModel(model); 46 | QTableView::setModel(m_pSortFilterModel); 47 | } 48 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/customtableview.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMTABLE_H 2 | #define CUSTOMTABLE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "CustomModelView/customhorizontalheaderview.h" 11 | 12 | // 1. 先实现正常的视图/模型显示 13 | // 2. 再实现定制表头 14 | // 3. 处理选择 15 | // 4. 实现右键菜单 16 | // 5. 在不同的View之间交互跳转, QListView/QTreeView/QTableView 17 | 18 | 19 | /* 自定义TableView, 用来在表头进行过滤筛选及排序等操作 */ 20 | class CustomTableView : public QTableView 21 | { 22 | Q_OBJECT 23 | public: 24 | explicit CustomTableView(QWidget *parent = nullptr); 25 | void setModel(QAbstractItemModel *model) override; 26 | 27 | private: 28 | void initConnect(); 29 | 30 | private: 31 | CustomHorizontalHeaderView *m_pHHeaderView; 32 | QSortFilterProxyModel *m_pSortFilterModel; 33 | }; 34 | 35 | #endif // CUSTOMTABLE_H 36 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/customtreeview.cpp: -------------------------------------------------------------------------------- 1 | #include "customtreeview.h" 2 | 3 | CustomTreeView::CustomTreeView(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /FramelessWindow/CustomModelView/customtreeview.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMTREEVIEW_H 2 | #define CUSTOMTREEVIEW_H 3 | 4 | #include 5 | #include 6 | 7 | class CustomTreeView : public QObject 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit CustomTreeView(QObject *parent = nullptr); 12 | 13 | signals: 14 | 15 | public slots: 16 | }; 17 | 18 | #endif // CUSTOMTREEVIEW_H 19 | -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/framelesswidget.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "framelesswidget.h" 6 | #include "ui_framelesswidget.h" 7 | #include 8 | 9 | FramelessWidget::FramelessWidget(bool isMax, bool isFull, QWidget *parent) : 10 | FramelessWidget(parent) 11 | { 12 | m_isMax = isMax; 13 | m_isFull = isMax ? isFull : false; 14 | ui->toolButton_max->setVisible(m_isMax); 15 | } 16 | 17 | FramelessWidget::FramelessWidget(QWidget *parent) : 18 | QWidget(parent), 19 | ui(new Ui::FramelessWidget) 20 | { 21 | ui->setupUi(this); 22 | setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint); 23 | // append minimize button flag in case of windows, 24 | // for correct windows native handling of minimize function 25 | #if defined(Q_OS_WIN) 26 | setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint); 27 | #endif 28 | setAttribute(Qt::WA_NoSystemBackground); 29 | setAttribute(Qt::WA_TranslucentBackground); 30 | ui->toolButton_restore->setVisible(false); 31 | ui->toolButton_full->setVisible(false); 32 | ui->toolButton_full_exit->setVisible(false); 33 | 34 | // shadow under window title text 35 | QGraphicsDropShadowEffect *textShadow = new QGraphicsDropShadowEffect; 36 | textShadow->setBlurRadius(4.0); 37 | textShadow->setColor(QColor(0, 0, 0)); 38 | textShadow->setOffset(0.0); 39 | ui->label_title->setGraphicsEffect(textShadow); 40 | this->styleWindow(true, true); 41 | QWidget::setWindowTitle(tr("FrameLessWidget")); 42 | 43 | QObject::connect(qApp, &QGuiApplication::applicationStateChanged, this, 44 | &FramelessWidget::on_applicationStateChanged); 45 | setMouseTracking(true); 46 | this->setWindowIcon(QIcon(":/images/icon.png")); 47 | QApplication::instance()->installEventFilter(this); 48 | } 49 | 50 | FramelessWidget::~FramelessWidget() 51 | { 52 | delete ui; 53 | } 54 | 55 | void FramelessWidget::setWindowTitle(const QString &text) 56 | { 57 | ui->label_title->setText(text); 58 | QWidget::setWindowTitle(text); 59 | } 60 | void FramelessWidget::setWindowIcon(const QIcon &ico) 61 | { 62 | ui->label_icon->setPixmap(ico.pixmap(24, 24)); 63 | // 能改变窗口任务栏的图标 64 | // QWidget::setWindowIcon(ico); 65 | } 66 | void FramelessWidget::setContent(QWidget *w) 67 | { 68 | QHBoxLayout *pHlayout = new QHBoxLayout; 69 | pHlayout->addWidget(w); 70 | pHlayout->setMargin(0); 71 | ui->windowContent->setLayout(pHlayout); 72 | } 73 | void FramelessWidget::setLayout(QLayout *layout) 74 | { 75 | QWidget *pWidget = new QWidget(this); 76 | pWidget->setLayout(layout); 77 | pWidget->setContentsMargins(0, 0, 0, 0); 78 | setContent(pWidget); 79 | } 80 | 81 | void FramelessWidget::on_applicationStateChanged(Qt::ApplicationState state) 82 | { 83 | if (windowState().testFlag(Qt::WindowNoState)) { 84 | styleWindow(state == Qt::ApplicationActive, true); 85 | } else if (windowState().testFlag(Qt::WindowFullScreen)) { 86 | styleWindow(state == Qt::ApplicationActive, false); 87 | } 88 | } 89 | 90 | 91 | void FramelessWidget::on_toolButton_close_clicked() { this->close(); } 92 | 93 | void FramelessWidget::on_toolButton_max_clicked() 94 | { 95 | ui->toolButton_restore->setVisible(true); 96 | ui->toolButton_max->setVisible(false); 97 | if(m_isFull){ 98 | ui->toolButton_full->setVisible(true); 99 | } 100 | this->setWindowState(Qt::WindowMaximized); 101 | this->showMaximized(); 102 | this->styleWindow(true, false); 103 | this->update(); 104 | } 105 | 106 | void FramelessWidget::on_toolButton_restore_clicked() 107 | { 108 | ui->toolButton_restore->setVisible(false); 109 | ui->toolButton_max->setVisible(true); 110 | ui->toolButton_full->setVisible(false); 111 | setWindowState(Qt::WindowNoState); 112 | this->styleWindow(true, true); 113 | this->update(); 114 | } 115 | 116 | void FramelessWidget::on_toolButton_min_clicked() 117 | { 118 | this->showMinimized(); 119 | this->update(); 120 | } 121 | 122 | void FramelessWidget::on_toolButton_full_clicked() 123 | { 124 | ui->toolButton_restore->setVisible(false); 125 | ui->toolButton_max->setVisible(false); 126 | ui->toolButton_full->setVisible(false); 127 | ui->toolButton_min->setVisible(false); 128 | ui->toolButton_close->setVisible(false); 129 | ui->toolButton_full_exit->setVisible(true); 130 | // 设置了Qt::WA_TranslucentBackground属性后无法直接调用showFullScreen接口实现全屏 131 | m_fullPoint = QPoint(this->geometry().x(), this->geometry().y()); 132 | m_fullSize = QSize(this->geometry().width(), this->geometry().height()); 133 | QDesktopWidget *deskdop = QApplication::desktop(); 134 | this->move(0, 0); 135 | this->resize(deskdop->width(), deskdop->height()); 136 | this->setWindowState(Qt::WindowFullScreen); 137 | this->update(); 138 | } 139 | 140 | void FramelessWidget::on_toolButton_full_exit_clicked() 141 | { 142 | ui->toolButton_restore->setVisible(true); 143 | ui->toolButton_max->setVisible(false); 144 | ui->toolButton_full->setVisible(true); 145 | ui->toolButton_min->setVisible(true); 146 | ui->toolButton_close->setVisible(true); 147 | ui->toolButton_full_exit->setVisible(false); 148 | this->move(m_fullPoint); 149 | this->resize(m_fullSize); 150 | this->setWindowState(Qt::WindowMaximized); 151 | this->update(); 152 | } 153 | 154 | void FramelessWidget::styleWindow(bool bActive, bool bNoState) 155 | { 156 | auto setShadow = [this](QColor color){ 157 | #if defined(Q_OS_WIN) 158 | this->layout()->setMargin(15); 159 | #else 160 | this->layout()->setMargin(0); 161 | #endif 162 | QGraphicsEffect *oldShadow = ui->windowFrame->graphicsEffect(); 163 | if (oldShadow){delete oldShadow;} 164 | QGraphicsDropShadowEffect *windowShadow = new QGraphicsDropShadowEffect; 165 | windowShadow->setBlurRadius(9.0); 166 | windowShadow->setColor(color); 167 | windowShadow->setOffset(0); 168 | ui->windowFrame->setGraphicsEffect(windowShadow); 169 | }; 170 | auto clearShadow = [this](){ 171 | this->layout()->setMargin(0); 172 | QGraphicsEffect *oldShadow = ui->windowFrame->graphicsEffect(); 173 | if (oldShadow) delete oldShadow; 174 | ui->windowFrame->setGraphicsEffect(nullptr); 175 | }; 176 | auto color = palette().color(bActive ? QPalette::Highlight : QPalette::Shadow); 177 | if(bNoState){ 178 | setShadow(color); 179 | }else{ 180 | clearShadow(); 181 | } 182 | } 183 | 184 | bool FramelessWidget::eventFilter(QObject *obj, QEvent *event) { 185 | // check mouse move event when mouse is moved on any object 186 | if (event->type() == QEvent::MouseMove) { 187 | if (isMaximized() || isFullScreen()) { 188 | return QWidget::eventFilter(obj, event); 189 | } 190 | QMouseEvent *pMouse = dynamic_cast(event); 191 | if (pMouse) { 192 | checkBorderDragging(pMouse); 193 | if(obj == ui->windowTitlebar && m_bMousePressedTitle){ 194 | move(m_wndPos + (pMouse->globalPos() - m_mousePos)); 195 | } 196 | } 197 | } 198 | // press is triggered only on frame window 199 | else if (event->type() == QEvent::MouseButtonPress && obj == this) { 200 | QMouseEvent *pMouse = dynamic_cast(event); 201 | if (pMouse) { 202 | mousePressEvent(pMouse); 203 | } 204 | } else if(event->type() == QEvent::MouseButtonPress && obj == ui->windowTitlebar){ 205 | QMouseEvent *pMouse = dynamic_cast(event); 206 | if (pMouse) { 207 | this->m_bMousePressedTitle = true; 208 | this->m_mousePos = pMouse->globalPos(); 209 | this->m_wndPos = this->pos(); 210 | } 211 | } else if (event->type() == QEvent::MouseButtonRelease && obj == this) { 212 | if (m_bMousePressed) { 213 | QMouseEvent *pMouse = dynamic_cast(event); 214 | if (pMouse) { 215 | mouseReleaseEvent(pMouse); 216 | } 217 | } 218 | } else if(event->type() == QEvent::MouseButtonRelease && obj == ui->windowTitlebar){ 219 | m_bMousePressedTitle = false; 220 | } else if(event->type() == QEvent::MouseButtonDblClick && obj == ui->windowTitlebar){ 221 | if(windowState().testFlag(Qt::WindowNoState) && m_isMax){ 222 | this->on_toolButton_max_clicked(); 223 | }else if(windowState().testFlag(Qt::WindowFullScreen)){ 224 | this->on_toolButton_full_exit_clicked(); 225 | }else if(windowState().testFlag(Qt::WindowMaximized)){ 226 | this->on_toolButton_restore_clicked(); 227 | } 228 | } 229 | 230 | return QWidget::eventFilter(obj, event); 231 | } 232 | 233 | // pos in global virtual desktop coordinates 234 | bool FramelessWidget::leftBorderHit(const QPoint &pos) { 235 | const QRect &rect = this->geometry(); 236 | if (pos.x() >= rect.x() && pos.x() <= rect.x() + CONST_DRAG_BORDER_SIZE) { 237 | return true; 238 | } 239 | return false; 240 | } 241 | 242 | bool FramelessWidget::rightBorderHit(const QPoint &pos) { 243 | const QRect &rect = this->geometry(); 244 | int tmp = rect.x() + rect.width(); 245 | if (pos.x() <= tmp && pos.x() >= (tmp - CONST_DRAG_BORDER_SIZE)) { 246 | return true; 247 | } 248 | return false; 249 | } 250 | 251 | bool FramelessWidget::topBorderHit(const QPoint &pos) { 252 | const QRect &rect = this->geometry(); 253 | if (pos.y() >= rect.y() && pos.y() <= rect.y() + CONST_DRAG_BORDER_SIZE) { 254 | return true; 255 | } 256 | return false; 257 | } 258 | 259 | bool FramelessWidget::bottomBorderHit(const QPoint &pos) { 260 | const QRect &rect = this->geometry(); 261 | int tmp = rect.y() + rect.height(); 262 | if (pos.y() <= tmp && pos.y() >= (tmp - CONST_DRAG_BORDER_SIZE)) { 263 | return true; 264 | } 265 | return false; 266 | } 267 | 268 | void FramelessWidget::mousePressEvent(QMouseEvent *event) { 269 | if (isMaximized()) { return; } 270 | 271 | m_bMousePressed = true; 272 | m_StartGeometry = this->geometry(); 273 | 274 | QPoint globalMousePos = mapToGlobal(QPoint(event->x(), event->y())); 275 | 276 | if (leftBorderHit(globalMousePos) && topBorderHit(globalMousePos)) { 277 | m_bDragTop = true; 278 | m_bDragLeft = true; 279 | setCursor(Qt::SizeFDiagCursor); 280 | } else if (rightBorderHit(globalMousePos) && topBorderHit(globalMousePos)) { 281 | m_bDragRight = true; 282 | m_bDragTop = true; 283 | setCursor(Qt::SizeBDiagCursor); 284 | } else if (leftBorderHit(globalMousePos) && bottomBorderHit(globalMousePos)) { 285 | m_bDragLeft = true; 286 | m_bDragBottom = true; 287 | setCursor(Qt::SizeBDiagCursor); 288 | } else if(rightBorderHit(globalMousePos) && bottomBorderHit(globalMousePos)){ 289 | m_bDragBottom = true; 290 | m_bDragRight = true; 291 | setCursor(Qt::SizeFDiagCursor); 292 | } else { 293 | if (topBorderHit(globalMousePos)) { 294 | m_bDragTop = true; 295 | setCursor(Qt::SizeVerCursor); 296 | } else if (leftBorderHit(globalMousePos)) { 297 | m_bDragLeft = true; 298 | setCursor(Qt::SizeHorCursor); 299 | } else if (rightBorderHit(globalMousePos)) { 300 | m_bDragRight = true; 301 | setCursor(Qt::SizeHorCursor); 302 | } else if (bottomBorderHit(globalMousePos)) { 303 | m_bDragBottom = true; 304 | setCursor(Qt::SizeVerCursor); 305 | } 306 | } 307 | } 308 | 309 | void FramelessWidget::mouseReleaseEvent(QMouseEvent *event) { 310 | Q_UNUSED(event); 311 | if (isMaximized()) { return; } 312 | 313 | m_bMousePressed = false; 314 | bool bSwitchBackCursorNeeded = m_bDragTop || m_bDragLeft || m_bDragRight || m_bDragBottom; 315 | m_bDragTop = false; 316 | m_bDragLeft = false; 317 | m_bDragRight = false; 318 | m_bDragBottom = false; 319 | if (bSwitchBackCursorNeeded) { setCursor(Qt::ArrowCursor); } 320 | } 321 | 322 | void FramelessWidget::checkBorderDragging(QMouseEvent *event) { 323 | if (isMaximized() || isFullScreen()) { return; } 324 | 325 | QPoint globalMousePos = event->globalPos(); 326 | if (m_bMousePressed) { 327 | if (m_bDragTop && m_bDragRight) { 328 | int newHeight = m_StartGeometry.height() + m_StartGeometry.y() - globalMousePos.y(); 329 | int newWidth = globalMousePos.x() - m_StartGeometry.x(); 330 | if (newHeight > this->minimumHeight() && newWidth > this->minimumWidth()) { 331 | setGeometry(m_StartGeometry.x(), globalMousePos.y(), newWidth, newHeight); 332 | } 333 | }else if (m_bDragTop && m_bDragLeft) { 334 | int newHeight = m_StartGeometry.height() + m_StartGeometry.y() - globalMousePos.y(); 335 | int newWidth = m_StartGeometry.width() + m_StartGeometry.x() - globalMousePos.x(); 336 | if (newHeight > this->minimumHeight() && newWidth > this->minimumWidth()) { 337 | setGeometry(globalMousePos.x(), globalMousePos.y(), newWidth, newHeight); 338 | } 339 | }else if (m_bDragBottom && m_bDragLeft) { 340 | int newHeight = globalMousePos.y() - m_StartGeometry.y(); 341 | int newWidth = m_StartGeometry.width() + m_StartGeometry.x() - globalMousePos.x(); 342 | if (newHeight > this->minimumHeight() && newWidth > this->minimumWidth()) { 343 | setGeometry(globalMousePos.x(), m_StartGeometry.y(), newWidth, newHeight); 344 | } 345 | } else if (m_bDragBottom && m_bDragRight) { 346 | int newHeight = globalMousePos.y() - m_StartGeometry.y(); 347 | int newWidth = globalMousePos.x() - m_StartGeometry.x(); 348 | if (newHeight > this->minimumHeight() && newWidth > this->minimumWidth()) { 349 | resize(newWidth, newHeight); 350 | } 351 | } else if (m_bDragTop) { 352 | int newHeight = m_StartGeometry.height() + m_StartGeometry.y() - globalMousePos.y(); 353 | if (newHeight > this->minimumHeight()) { 354 | setGeometry(m_StartGeometry.x(), globalMousePos.y(), m_StartGeometry.width(),newHeight); 355 | } 356 | } else if (m_bDragLeft) { 357 | int newWidth = m_StartGeometry.width() + m_StartGeometry.x() - globalMousePos.x(); 358 | if (newWidth > this->minimumWidth()) { 359 | setGeometry(globalMousePos.x(), m_StartGeometry.y(), newWidth, m_StartGeometry.height()); 360 | } 361 | } else if (m_bDragRight) { 362 | int newWidth = globalMousePos.x() - m_StartGeometry.x(); 363 | if (newWidth > this->minimumWidth()) { 364 | resize(newWidth, m_StartGeometry.height()); 365 | } 366 | } else if (m_bDragBottom) { 367 | int newHeight = globalMousePos.y() - m_StartGeometry.y(); 368 | if (newHeight > this->minimumHeight()) { 369 | resize(m_StartGeometry.width(), newHeight); 370 | } 371 | } 372 | } else { 373 | // no mouse pressed 374 | if (leftBorderHit(globalMousePos) && topBorderHit(globalMousePos)) { 375 | setCursor(Qt::SizeFDiagCursor); 376 | } else if (rightBorderHit(globalMousePos) && topBorderHit(globalMousePos)) { 377 | setCursor(Qt::SizeBDiagCursor); 378 | } else if (leftBorderHit(globalMousePos) && bottomBorderHit(globalMousePos)) { 379 | setCursor(Qt::SizeBDiagCursor); 380 | } else if(rightBorderHit(globalMousePos) && bottomBorderHit(globalMousePos)){ 381 | setCursor(Qt::SizeFDiagCursor); 382 | } else { 383 | if (topBorderHit(globalMousePos)) { 384 | setCursor(Qt::SizeVerCursor); 385 | } else if (leftBorderHit(globalMousePos)) { 386 | setCursor(Qt::SizeHorCursor); 387 | } else if (rightBorderHit(globalMousePos)) { 388 | setCursor(Qt::SizeHorCursor); 389 | } else if (bottomBorderHit(globalMousePos)) { 390 | setCursor(Qt::SizeVerCursor); 391 | } else { 392 | m_bDragTop = false; 393 | m_bDragLeft = false; 394 | m_bDragRight = false; 395 | m_bDragBottom = false; 396 | setCursor(Qt::ArrowCursor); 397 | } 398 | } 399 | } 400 | } 401 | -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/framelesswidget.h: -------------------------------------------------------------------------------- 1 | #ifndef FRAMELESSWIDGET_H 2 | #define FRAMELESSWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Ui { 13 | class FramelessWidget; 14 | } 15 | 16 | // TODO: 完成Demo示例,尽可能多的添加控件的样式 17 | 18 | class FramelessWidget : public QWidget 19 | { 20 | Q_OBJECT 21 | 22 | public: 23 | explicit FramelessWidget(QWidget *parent = nullptr); 24 | explicit FramelessWidget(bool isMax, bool isFull=true, QWidget *parent = nullptr); 25 | virtual ~FramelessWidget(); 26 | // 重载, title, ico, layou三个函数 27 | void setWindowTitle(const QString &text); 28 | void setWindowIcon(const QIcon &ico); 29 | void setLayout(QLayout *layout); 30 | 31 | void setContent(QWidget *w); 32 | 33 | private slots: 34 | // 根据窗口状态改变窗口的阴影 35 | void on_applicationStateChanged(Qt::ApplicationState state); 36 | void on_toolButton_close_clicked(); 37 | void on_toolButton_max_clicked(); 38 | void on_toolButton_restore_clicked(); 39 | void on_toolButton_min_clicked(); 40 | // 全屏进入和退出处理,在最大化才会显示全屏按钮 41 | void on_toolButton_full_clicked(); 42 | void on_toolButton_full_exit_clicked(); 43 | // 绘制窗口阴影, bActive:窗口是否激活, bNoState: 正常状态 44 | void styleWindow(bool bActive, bool bNoState); 45 | bool leftBorderHit(const QPoint &pos); 46 | bool rightBorderHit(const QPoint &pos); 47 | bool topBorderHit(const QPoint &pos); 48 | bool bottomBorderHit(const QPoint &pos); 49 | 50 | protected: 51 | virtual bool eventFilter(QObject *obj, QEvent *event); 52 | virtual void mousePressEvent(QMouseEvent *event); 53 | virtual void mouseReleaseEvent(QMouseEvent *event); 54 | virtual void checkBorderDragging(QMouseEvent *event); 55 | 56 | private: 57 | Ui::FramelessWidget *ui; 58 | QRect m_StartGeometry; 59 | const quint8 CONST_DRAG_BORDER_SIZE = 15; 60 | bool m_bMousePressed = false; 61 | bool m_bMousePressedTitle = false; 62 | bool m_bDragTop = false; 63 | bool m_bDragLeft = false; 64 | bool m_bDragRight = false; 65 | bool m_bDragBottom = false; 66 | QPoint m_mousePos; 67 | QPoint m_wndPos; 68 | 69 | // 全屏之前的窗口位置和尺寸 70 | QPoint m_fullPoint; 71 | QSize m_fullSize; 72 | 73 | // 是否显示全屏按钮和最大化按钮 74 | bool m_isFull = true; 75 | bool m_isMax = true; 76 | }; 77 | 78 | class CustomWarningBox : public FramelessWidget{ 79 | Q_OBJECT 80 | public: 81 | explicit CustomWarningBox(QString title, QString info, QWidget *parent=nullptr) : 82 | FramelessWidget(parent) 83 | { 84 | this->setWindowTitle(title); 85 | m_pInfo = new QLabel(info); 86 | m_pInfo->setStyleSheet("font-size: 24px; color: rgb(255, 170, 0);"); 87 | m_pInfo->setAlignment(Qt::AlignCenter); 88 | QHBoxLayout *pLayout = new QHBoxLayout(); 89 | pLayout->addWidget(m_pInfo); 90 | this->setLayout(pLayout); 91 | this->setWindowModality(Qt::ApplicationModal); 92 | this->resize(300, 100); 93 | } 94 | virtual ~CustomWarningBox(){} 95 | void setInfo(QString info){ 96 | m_pInfo->setText(info); 97 | } 98 | static void customWarningBox(QString title, QString info){ 99 | static CustomWarningBox handle(title, info); 100 | handle.setInfo(info); 101 | handle.setWindowTitle(title); 102 | handle.show(); 103 | } 104 | private: 105 | QLabel *m_pInfo; 106 | }; 107 | 108 | class CustomErrorBox : public FramelessWidget{ 109 | Q_OBJECT 110 | public: 111 | explicit CustomErrorBox(QString title, QString info, QWidget *parent=nullptr) : 112 | FramelessWidget(parent) 113 | { 114 | this->setWindowTitle(title); 115 | m_pInfo = new QLabel(info); 116 | m_pInfo->setStyleSheet("font-size: 24px; color: rgb(240, 0, 0);"); 117 | m_pInfo->setAlignment(Qt::AlignCenter); 118 | QHBoxLayout *pLayout = new QHBoxLayout(); 119 | pLayout->addWidget(m_pInfo); 120 | setLayout(pLayout); 121 | this->setWindowModality(Qt::ApplicationModal); 122 | this->resize(300, 100); 123 | } 124 | 125 | virtual ~CustomErrorBox(){} 126 | void setInfo(QString info){ 127 | m_pInfo->setText(info); 128 | } 129 | static void customErrorBox(QString title, QString info){ 130 | static CustomErrorBox handle(title, info); 131 | handle.setInfo(info); 132 | handle.setWindowTitle(title); 133 | handle.show(); 134 | } 135 | private: 136 | QLabel *m_pInfo; 137 | }; 138 | 139 | class CustomInfoBox : public FramelessWidget{ 140 | Q_OBJECT 141 | public: 142 | explicit CustomInfoBox(QString title, QString info, QWidget *parent=nullptr) : 143 | FramelessWidget(parent) 144 | { 145 | this->setWindowTitle(title); 146 | m_pInfo = new QLabel(info); 147 | m_pInfo->setStyleSheet("font-size: 24px; color: rgb(0, 0, 0);"); 148 | m_pInfo->setAlignment(Qt::AlignCenter); 149 | QHBoxLayout *pLayout = new QHBoxLayout(); 150 | pLayout->addWidget(m_pInfo); 151 | this->setLayout(pLayout); 152 | this->setWindowModality(Qt::ApplicationModal); 153 | this->resize(300, 100); 154 | } 155 | virtual ~CustomInfoBox(){} 156 | void setInfo(QString info){ 157 | m_pInfo->setText(info); 158 | } 159 | static void customInfoBox(QString title, QString info){ 160 | static CustomInfoBox handle(title, info); 161 | handle.setInfo(info); 162 | handle.setWindowTitle(title); 163 | handle.show(); 164 | } 165 | private: 166 | QLabel *m_pInfo; 167 | }; 168 | 169 | class CustomProgressbar: public FramelessWidget{ 170 | Q_OBJECT 171 | public: 172 | explicit CustomProgressbar(QString title, QString info, QWidget *parent=nullptr) : 173 | FramelessWidget(parent) 174 | { 175 | this->setWindowTitle(title); 176 | pPro = new QProgressBar; 177 | pInfo = new QLabel(info); 178 | QHBoxLayout *pLayout = new QHBoxLayout(); 179 | pLayout->addWidget(pInfo); 180 | pLayout->addWidget(pPro); 181 | this->setLayout(pLayout); 182 | this->setWindowModality(Qt::ApplicationModal); 183 | this->resize(300, 80); 184 | } 185 | virtual ~CustomProgressbar(){} 186 | 187 | public slots: 188 | void onSetValue(int value){ 189 | this->pPro->setValue(value); 190 | if(value == this->pPro->maximum()){ 191 | QTimer::singleShot(500, this, &CustomProgressbar::close); 192 | } 193 | } 194 | void onSetError(QString msg) { 195 | this->pInfo->setText(msg); 196 | } 197 | void onSetRange(int min, int max){ 198 | this->onSetValue(0); 199 | this->pPro->setRange(min, max); 200 | } 201 | private: 202 | QProgressBar *pPro; 203 | QLabel *pInfo; 204 | }; 205 | 206 | #endif // FRAMELESSWIDGET_H 207 | -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/framelesswidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | FramelessWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 645 10 | 431 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | FramelessWidget 21 | 22 | 23 | /* 常用控件样式 */ 24 | /* 状态栏 */ 25 | QStatusBar{ 26 | background-color: #117ee0; 27 | } 28 | QStatusBar::item{ 29 | border: none; 30 | } 31 | /* 分裂器 */ 32 | QSplitter::handle { 33 | background-color: #117ee0; 34 | border: none; 35 | } 36 | 37 | QSplitter::handle:horizontal { 38 | width: 8px; 39 | } 40 | 41 | QSplitter::handle:vertical { 42 | height: 8px; 43 | } 44 | 45 | QSplitter::handle:pressed { 46 | background-color: #c2c2c2; 47 | } 48 | QComboBox QAbstractItemView 49 | { 50 | border: none; 51 | } 52 | QComboBox QAbstractItemView::item 53 | { 54 | color: rgb(0, 0, 0); 55 | min-height: 30px; 56 | } 57 | QComboBox QAbstractItemView::item:hover { 58 | color: rgb(255, 255, 255); 59 | background-color: rgba(0, 120, 215, 0.5); 60 | } 61 | QComboBox { 62 | min-height: 20px; 63 | border: 1px solid gray; 64 | background-color: rgb(255, 255, 255); 65 | color: #000000; 66 | padding: 1px 5px 1px 5px; 67 | } 68 | QComboBox::drop-down { 69 | subcontrol-origin: padding; 70 | subcontrol-position: top right; 71 | background-color: rgb(255, 255, 255); 72 | border-left-width: 1px; 73 | border-left-color: darkgray; 74 | border-left-style: solid; 75 | } 76 | QComboBox::down-arrow { 77 | image: url(:/images/sort_down.png); 78 | background-color: transparent; 79 | width: 12px; 80 | height: 12px; 81 | } 82 | QComboBox::drop-down:hover { 83 | background-color: darkgray; 84 | } 85 | QLabel{ 86 | min-height: 20px; 87 | color: #000000; 88 | background-color: transparent; 89 | } 90 | 91 | QDateTimeEdit, 92 | QSpinBox, 93 | QDoubleSpinBox, 94 | QLineEdit{ 95 | padding-left: 2px; 96 | min-height: 20px; 97 | border: 1px solid gray; 98 | background-color: rgb(255, 255, 255); 99 | selection-background-color: #0078D7; 100 | } 101 | QDateTimeEdit:!enabled, 102 | QDoubleSpinBox:!enabled, 103 | QSpinBox:!enabled, 104 | QLineEdit:!enabled{ 105 | background-color: rgb(220, 220, 220); 106 | } 107 | QDateTimeEdit:enabled:hover, 108 | QDateTimeEdit:enabled:focus, 109 | QDoubleSpinBox:enabled:hover, 110 | QDoubleSpinBox:enabled:focus, 111 | QSpinBox:enabled:hover, 112 | QSpinBox:enabled:focus, 113 | QLineEdit:enabled:hover, 114 | QLineEdit:enabled:focus{ 115 | border: 1px solid #3190EE; 116 | } 117 | 118 | QDateTimeEdit::up-button, 119 | QDoubleSpinBox::up-button, 120 | QSpinBox::up-button { 121 | subcontrol-origin: border; 122 | subcontrol-position: top right; 123 | width: 14px; 124 | height: 10px; 125 | padding: 1px; 126 | image: url(:/images/sort_up.png); 127 | } 128 | QDateTimeEdit::up-button:pressed, 129 | QDoubleSpinBox::up-button:pressed, 130 | QDateTimeEdit::up-button:hover, 131 | QDoubleSpinBox::up-button:hover, 132 | QSpinBox::up-button:pressed, 133 | QSpinBox::up-button:hover { 134 | background-color: darkgray; 135 | } 136 | QDateTimeEdit::up-arrow, 137 | QDoubleSpinBox::up-arrow, 138 | QSpinBox::up-arrow { 139 | image: url(:/images/sort_up.png); 140 | width: 6px; 141 | height: 6px; 142 | } 143 | QDateTimeEdit::down-button, 144 | QDoubleSpinBox::down-button, 145 | QSpinBox::down-button { 146 | subcontrol-origin: border; 147 | subcontrol-position: bottom right; 148 | width: 14px; 149 | height: 10px; 150 | padding: 1px; 151 | image: url(:/images/sort_down.png); 152 | } 153 | QDateTimeEdit::down-button:pressed, 154 | QDoubleSpinBox::down-button:pressed, 155 | QDateTimeEdit::down-button:hover, 156 | QDoubleSpinBox::down-button:hover, 157 | QSpinBox::down-button:pressed, 158 | QSpinBox::down-button:hover { 159 | background-color: darkgray; 160 | } 161 | QDateTimeEdit::down-arrow, 162 | QDoubleSpinBox::down-arrow, 163 | QSpinBox::down-arrow { 164 | image: url(:/images/sort_down.png); 165 | width: 6px; 166 | height: 6px; 167 | } 168 | 169 | QProgressBar { 170 | border: 1px solid grey; 171 | text-align: right; 172 | color: #177fd8; 173 | margin-right: 25px; 174 | } 175 | QProgressBar::chunk { 176 | background-color: #3096f8; 177 | width: 10px; 178 | margin: 0.5px; 179 | } 180 | 181 | QGroupBox { 182 | background-color: transparent; 183 | border: 1px solid gray; 184 | border-radius: 10px; 185 | margin-top: 2ex; 186 | } 187 | QGroupBox::title { 188 | subcontrol-origin: margin; 189 | subcontrol-position: top center; 190 | padding: 0 2px; /* y方向, x方向 */ 191 | } 192 | QGroupBox::indicator { 193 | spacing: 5px; 194 | width: 15px; 195 | height: 15px; 196 | color: #000000; 197 | background-color: transparent; 198 | } 199 | QGroupBox::indicator:unchecked { 200 | image: url(:/images/checkbox.png); 201 | } 202 | QGroupBox::indicator:checked { 203 | image: url(:/images/checkbox--checked.png); 204 | } 205 | 206 | QToolButton, 207 | QPushButton{ 208 | border-radius:4px; 209 | min-height: 20px; 210 | padding-left: 6px; 211 | padding-right: 6px; 212 | background-color: #3096f8; 213 | color: #FFFFFF; 214 | } 215 | QToolButton:hover, 216 | QPushButton:hover{ 217 | background-color: #177fd8; 218 | border: 1px solid #00DDCC; 219 | color: #FFFFFF; 220 | } 221 | QToolButton:pressed, 222 | QPushButton:pressed{ 223 | background-color: #177fd8; 224 | color: #FFFFFF; 225 | } 226 | QToolButton::checked, 227 | QPushButton::checked{ 228 | background-color: #177fd8; 229 | color: #FFFFFF; 230 | } 231 | QToolButton:disabled, 232 | QPushButton:disabled{ 233 | background-color: darkgray; 234 | color: #000000; 235 | } 236 | 237 | QRadioButton, 238 | QCheckBox { 239 | spacing: 5px; 240 | color: #000000; 241 | background-color: transparent; 242 | } 243 | QRadioButton::indicator, 244 | QCheckBox::indicator { 245 | width: 20px; 246 | height: 20px; 247 | } 248 | 249 | QCheckBox::indicator:unchecked { 250 | image: url(:/images/checkbox.png); 251 | } 252 | QCheckBox::indicator:checked { 253 | image: url(:/images/checkbox--checked.png); 254 | } 255 | QRadioButton::indicator:checked:hover, 256 | QRadioButton::indicator:unchecked:hover, 257 | QRadioButton::indicator:checked:pressed, 258 | QRadioButton::indicator:unchecked:pressed, 259 | QCheckBox::indicator:checked:hover, 260 | QCheckBox::indicator:unchecked:hover, 261 | QCheckBox::indicator:checked:pressed, 262 | QCheckBox::indicator:unchecked:pressed { 263 | background-color: rgba(23, 127, 216, 0.1); 264 | } 265 | QRadioButton::indicator:unchecked{ 266 | image: url(:/images/radio-button.png); 267 | } 268 | QRadioButton::indicator:checked{ 269 | image: url(:/images/radio-button--checked.png); 270 | } 271 | QRadioButton::indicator:disabled{ 272 | image: url(:/images/radio-button_dis.png); 273 | } 274 | QCheckBox::indicator:disabled{ 275 | image: url(:/images/checkbox_dis.png); 276 | } 277 | 278 | QScrollBar{ 279 | border:none; 280 | background-color: #DCDCDC; 281 | } 282 | QScrollBar:horizontal { 283 | height: 15px; 284 | padding-left: 15px; 285 | padding-right: 15px; 286 | } 287 | QScrollBar:vertical { 288 | width: 15px; 289 | padding-top: 15px; 290 | padding-bottom: 15px; 291 | } 292 | QScrollBar::add-page, QScrollBar::sub-page { 293 | background-color: transparent; 294 | } 295 | QScrollBar::handle { 296 | background: #3096f8; 297 | min-width: 15px; 298 | min-height: 15px 299 | } 300 | QScrollBar::add-line:vertical{ 301 | background-color: transparent; 302 | image:url(:/images/sort_down.png) center no-repeat; 303 | } 304 | QScrollBar::sub-line:vertical{ 305 | background-color: transparent; 306 | image:url(:/images/sort_up.png) center no-repeat; 307 | } 308 | QScrollBar::add-line:horizontal{ 309 | background-color: transparent; 310 | image:url(:/images/caret-right.png) center no-repeat; 311 | } 312 | QScrollBar::sub-line:horizontal{ 313 | background-color: transparent; 314 | image:url(:/images/caret-left.png) center no-repeat; 315 | } 316 | QScrollBar::add-line:hover, 317 | QScrollBar::sub-line:hover, 318 | QScrollBar::handle:hover{ 319 | background-color: rgba(23, 127, 216, 0.2); 320 | } 321 | QScrollBar::handle:pressed{ 322 | background-color: #177fd8; 323 | } 324 | 325 | QTextBrower, 326 | QTextEdit{ 327 | border: none; 328 | background-color: rgba(255, 255, 255, 0.9);; 329 | } 330 | 331 | QTabWidget::pane { /* The tab widget frame */ 332 | background-color: transparent; 333 | border: 1px solid gray; 334 | border-bottom-left-radius: 10px; 335 | border-bottom-right-radius: 10px; 336 | padding: 5px; 337 | } 338 | QTabWidget::tab-bar { 339 | background-color: #FFFFFF; 340 | alignment: left; 341 | } 342 | QTabBar::tab { 343 | background-color: #ddedfa; 344 | border: none; 345 | min-width: 40px; 346 | min-height: 15px; 347 | padding: 5px; 348 | margin: 1px; 349 | color: #000000; 350 | } 351 | QTabBar::tab:selected{ 352 | background-color: #177fd8; 353 | color: #FFFFFF; 354 | } 355 | QTabBar::tab:hover { 356 | background-color: #3096f8; 357 | color: #FFFFFF; 358 | } 359 | QTabBar::tab:only-one { 360 | margin: 0; 361 | } 362 | QTabBar::close-button { 363 | image: url(:/images/icon_window_close.png); 364 | subcontrol-position: right; 365 | } 366 | QTabBar::close-button:hover { 367 | background-color: #DC0000; 368 | } 369 | QTabBar QToolButton{ 370 | padding: 0px; 371 | } 372 | QTabBar QToolButton::right-arrow { /* the arrow mark in the tool buttons */ 373 | border-image: url(:/images/caret-right.png); 374 | } 375 | 376 | QTabBar QToolButton::left-arrow { 377 | border-image: url(:/images/caret-left.png); 378 | } 379 | 380 | /* 本窗口的样式 */ 381 | #windowFrame{ 382 | border: 2px solid rgb(194, 194, 194); 383 | gridline-color: rgb(194, 194, 194); 384 | border-radius: 1px 1px 1px 1px; 385 | background-color: palette(Window); 386 | } 387 | #windowTitlebar{ 388 | border: 0px none palette(base); 389 | border-top-left-radius:2px; 390 | border-top-right-radius:2px; 391 | border-bottom: 8px solid #117ee0; 392 | background-image: url(:/images/6.png); 393 | background-color: #237fca; 394 | color: #ffffff; 395 | } 396 | #windowTitlebar QToolButton{ 397 | background-color:none; 398 | border:none; 399 | width:16px; 400 | height:16px; 401 | padding:4px; 402 | min-height: 16px; 403 | border-radius:0px; 404 | color: #FFFFFF; 405 | } 406 | #windowTitlebar QToolButton:hover{ 407 | background-color: #2e9eea; 408 | border: none; 409 | color: #FFFFFF; 410 | } 411 | #windowTitlebar QToolButton:pressed{ 412 | background-color:palette(highlight); 413 | } 414 | #windowTitlebar #toolButton_close{ 415 | image: url(:/images/icon_window_close.png); 416 | } 417 | #windowTitlebar #toolButton_close:hover{ 418 | background-color: #DC0000; 419 | } 420 | #windowTitlebar #toolButton_close:pressed{ 421 | background-color: #F1707A; 422 | } 423 | #toolButton_max{ 424 | image: url(:/images/icon_window_maximize.png); 425 | } 426 | #toolButton_restore{ 427 | image: url(:/images/icon_window_restore.png); 428 | } 429 | #toolButton_min{ 430 | image: url(:/images/icon_window_minimize.png); 431 | } 432 | #toolButton_full{ 433 | image: url(:/images/fullscreen.png); 434 | } 435 | #toolButton_full_exit{ 436 | image: url(:/images/fullscreen_exit.png); 437 | } 438 | #windowTitlebar #label_title{ 439 | color: #ffffff; 440 | font-weight:bold; 441 | font-size:16px; 442 | } 443 | 444 | 445 | 446 | 447 | 448 | 449 | 5 450 | 451 | 452 | 5 453 | 454 | 455 | 5 456 | 457 | 458 | 5 459 | 460 | 461 | 0 462 | 463 | 464 | 465 | 466 | 467 | 0 468 | 469 | 470 | 0 471 | 472 | 473 | 0 474 | 475 | 476 | 0 477 | 478 | 479 | 0 480 | 481 | 482 | 483 | 484 | 485 | 0 486 | 0 487 | 488 | 489 | 490 | 491 | 0 492 | 50 493 | 494 | 495 | 496 | 497 | 16777215 498 | 50 499 | 500 | 501 | 502 | 503 | 0 504 | 505 | 506 | 0 507 | 508 | 509 | 510 | 511 | 512 | 24 513 | 20 514 | 515 | 516 | 517 | 518 | 24 519 | 24 520 | 521 | 522 | 523 | :/images/icon.png 524 | 525 | 526 | Qt::AlignCenter 527 | 528 | 529 | 530 | 531 | 532 | 533 | 软件标题 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 0 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | Qt::Vertical 592 | 593 | 594 | 595 | 20 596 | 40 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/6.png 4 | images/icon_window_close.png 5 | images/icon_window_maximize.png 6 | images/icon_window_minimize.png 7 | images/icon_window_restore.png 8 | images/fullscreen.png 9 | images/fullscreen_exit.png 10 | images/icon.png 11 | images/window.ico 12 | images/filter.png 13 | images/sort_down.png 14 | images/sort_up.png 15 | images/qt_zh_CN.qm 16 | images/caret-left.png 17 | images/caret-right.png 18 | images/checkbox.png 19 | images/checkbox--checked.png 20 | images/radio-button.png 21 | images/radio-button--checked.png 22 | images/checkbox_dis.png 23 | images/radio-button_dis.png 24 | 25 | 26 | -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/6.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/caret-left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/caret-left.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/caret-right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/caret-right.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/checkbox--checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/checkbox--checked.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/checkbox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/checkbox.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/checkbox_dis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/checkbox_dis.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/filter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/filter.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/fullscreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/fullscreen.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/fullscreen_exit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/fullscreen_exit.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/icon.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/icon_window_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/icon_window_close.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/icon_window_maximize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/icon_window_maximize.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/icon_window_minimize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/icon_window_minimize.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/icon_window_restore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/icon_window_restore.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/qt_zh_CN.qm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/qt_zh_CN.qm -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/radio-button--checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/radio-button--checked.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/radio-button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/radio-button.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/radio-button_dis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/radio-button_dis.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/sort_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/sort_down.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/sort_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/sort_up.png -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/window.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/window.ico -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/window.rc: -------------------------------------------------------------------------------- 1 | IDI_ICON1 ICON DISCARDABLE "window.ico" -------------------------------------------------------------------------------- /FramelessWindow/FrameLessWidget/images/界面20200103.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/FrameLessWidget/images/界面20200103.jpg -------------------------------------------------------------------------------- /FramelessWindow/FramelessWindow.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2020-04-01T11:41:47 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = FramelessWindow 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | CONFIG += c++11 26 | 27 | SOURCES += \ 28 | CustomModelView/customlineeditedelegate.cpp \ 29 | basicwidget.cpp \ 30 | main.cpp \ 31 | mainwindow.cpp\ 32 | CustomModelView/customheaderview.cpp \ 33 | CustomModelView/customhorizontalheaderview.cpp \ 34 | CustomModelView/customlistview.cpp \ 35 | CustomModelView/custommodel.cpp \ 36 | CustomModelView/customtableview.cpp \ 37 | CustomModelView/customtreeview.cpp \ 38 | FrameLessWidget/framelesswidget.cpp 39 | 40 | HEADERS += \ 41 | CustomModelView/customlineeditedelegate.h \ 42 | basicwidget.h \ 43 | mainwindow.h\ 44 | CustomModelView/customheaderview.h \ 45 | CustomModelView/customhorizontalheaderview.h \ 46 | CustomModelView/customlistview.h \ 47 | CustomModelView/custommodel.h \ 48 | CustomModelView/customtableview.h \ 49 | CustomModelView/customtreeview.h \ 50 | FrameLessWidget/framelesswidget.h 51 | 52 | FORMS += \ 53 | basicwidget.ui \ 54 | mainwindow.ui\ 55 | CustomModelView/customheaderview.ui \ 56 | FrameLessWidget/framelesswidget.ui 57 | 58 | # Default rules for deployment. 59 | qnx: target.path = /tmp/$${TARGET}/bin 60 | else: unix:!android: target.path = /opt/$${TARGET}/bin 61 | !isEmpty(target.path): INSTALLS += target 62 | 63 | 64 | 65 | RC_FILE += FrameLessWidget/images/window.rc 66 | 67 | RESOURCES += FrameLessWidget/images.qrc 68 | -------------------------------------------------------------------------------- /FramelessWindow/basicwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "basicwidget.h" 2 | #include "ui_basicwidget.h" 3 | 4 | BasicWidget::BasicWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::BasicWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | BasicWidget::~BasicWidget() 12 | { 13 | delete ui; 14 | } 15 | -------------------------------------------------------------------------------- /FramelessWindow/basicwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef BASICWIDGET_H 2 | #define BASICWIDGET_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class BasicWidget; 8 | } 9 | 10 | class BasicWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit BasicWidget(QWidget *parent = nullptr); 16 | ~BasicWidget(); 17 | 18 | private: 19 | Ui::BasicWidget *ui; 20 | }; 21 | 22 | #endif // BASICWIDGET_H 23 | -------------------------------------------------------------------------------- /FramelessWindow/basicwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | BasicWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 535 10 | 445 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | GroupBox 26 | 27 | 28 | Qt::AlignCenter 29 | 30 | 31 | false 32 | 33 | 34 | false 35 | 36 | 37 | 38 | 39 | 40 | CheckBox 41 | 42 | 43 | 44 | 45 | 46 | 47 | RadioButton 48 | 49 | 50 | buttonGroup 51 | 52 | 53 | 54 | 55 | 56 | 57 | RadioButton 58 | 59 | 60 | buttonGroup 61 | 62 | 63 | 64 | 65 | 66 | 67 | RadioButton 68 | 69 | 70 | buttonGroup 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | GroupBox 81 | 82 | 83 | 84 | 85 | 86 | PushButton 87 | 88 | 89 | 90 | 91 | 92 | 93 | false 94 | 95 | 96 | PushButton 97 | 98 | 99 | 100 | 101 | 102 | 103 | PushButton 104 | 105 | 106 | true 107 | 108 | 109 | true 110 | 111 | 112 | 113 | 114 | 115 | 116 | PushButton 117 | 118 | 119 | true 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 0 128 | 0 129 | 130 | 131 | 132 | ToolButton 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | true 143 | 144 | 145 | 0 146 | 147 | 148 | true 149 | 150 | 151 | false 152 | 153 | 154 | true 155 | 156 | 157 | false 158 | 159 | 160 | false 161 | 162 | 163 | 164 | true 165 | 166 | 167 | Text Edit 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | Tab Table 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | GroupBox 209 | 210 | 211 | false 212 | 213 | 214 | true 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | Qt::Horizontal 224 | 225 | 226 | 227 | 228 | 229 | 230 | 11111 231 | 232 | 233 | QLineEdit::Password 234 | 235 | 236 | 237 | 238 | 239 | 240 | Qt::Horizontal 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | Qt::Vertical 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | Lable 265 | 266 | 267 | 268 | 269 | 270 | 271 | false 272 | 273 | 274 | 0 275 | 276 | 277 | 10 278 | 279 | 280 | QComboBox::AdjustToContents 281 | 282 | 283 | 0 284 | 285 | 286 | 287 | 16 288 | 16 289 | 290 | 291 | 292 | false 293 | 294 | 295 | true 296 | 297 | 298 | 0 299 | 300 | 301 | 302 | 新建项目1 303 | 304 | 305 | 306 | 307 | 新建项目2 308 | 309 | 310 | 311 | 312 | 新建项目3 313 | 314 | 315 | 316 | 317 | 新建项目4 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | Qt::Horizontal 326 | 327 | 328 | 329 | 40 330 | 20 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | Disable Widget 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 80 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/darkstyle.qss: -------------------------------------------------------------------------------- 1 | QToolTip{ 2 | color:#ffffff; 3 | background-color:palette(base); 4 | border:1px solid palette(highlight); 5 | border-radius:4px; 6 | } 7 | QStatusBar{ 8 | background-color:qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 9 | color:palette(mid); 10 | } 11 | QMenuBar{ 12 | background-color:qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 13 | border-bottom:2px solid rgba(25,25,25,75); 14 | } 15 | QMenuBar::item{ 16 | spacing:2px; 17 | padding:3px 4px; 18 | background:transparent; 19 | } 20 | QMenuBar::item:selected{ 21 | background-color:qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(106,106,106,255),stop:1 rgba(106,106,106,75)); 22 | border-left:1px solid rgba(106,106,106,127); 23 | border-right:1px solid rgba(106,106,106,127); 24 | } 25 | QMenuBar::item:pressed{ 26 | background-color:palette(highlight); 27 | border-left:1px solid rgba(25,25,25,127); 28 | border-right:1px solid rgba(25,25,25,127); 29 | } 30 | QMenu{ 31 | background-color:palette(window); 32 | border:1px solid palette(shadow); 33 | } 34 | QMenu::item{ 35 | padding:3px 25px 3px 25px; 36 | border:1px solid transparent; 37 | } 38 | QMenu::item:disabled{ 39 | background-color:rgba(35,35,35,127); 40 | color:palette(disabled); 41 | } 42 | QMenu::item:selected{ 43 | border-color:rgba(147,191,236,127); 44 | background:palette(highlight); 45 | } 46 | QMenu::icon:checked{ 47 | background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 48 | border:1px solid palette(highlight); 49 | border-radius:2px; 50 | } 51 | QMenu::separator{ 52 | height:1px; 53 | background:palette(alternate-base); 54 | margin-left:5px; 55 | margin-right:5px; 56 | } 57 | QMenu::indicator{ 58 | width:18px; 59 | height:18px; 60 | } 61 | QMenu::indicator:non-exclusive:checked{ 62 | image:url(:/darkstyle/icon_checkbox_checked.png); 63 | padding-left:2px; 64 | } 65 | QMenu::indicator:non-exclusive:unchecked{ 66 | image:url(:/darkstyle/icon_checkbox_unchecked.png); 67 | padding-left:2px; 68 | } 69 | QMenu::indicator:exclusive:checked{ 70 | image:url(:/darkstyle/icon_radiobutton_checked.png); 71 | padding-left:2px; 72 | } 73 | QMenu::indicator:exclusive:unchecked{ 74 | image:url(:/darkstyle/icon_radiobutton_unchecked.png); 75 | padding-left:2px; 76 | } 77 | QToolBar::top{ 78 | background-color:qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 79 | border-bottom:3px solid qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 80 | } 81 | QToolBar::bottom{ 82 | background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 83 | border-top:3px solid qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 84 | } 85 | QToolBar::left{ 86 | background-color:qlineargradient(x1:0,y1:0,x2:1,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 87 | border-right:3px solid qlineargradient(x1:0,y1:0,x2:1,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 88 | } 89 | QToolBar::right{ 90 | background-color:qlineargradient(x1:1,y1:0,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 91 | border-left:3px solid qlineargradient(x1:1,y1:0,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 92 | } 93 | QMainWindow::separator{ 94 | width:6px; 95 | height:5px; 96 | padding:2px; 97 | } 98 | QSplitter::handle:horizontal{ 99 | width:10px; 100 | } 101 | QSplitter::handle:vertical{ 102 | height:10px; 103 | } 104 | QMainWindow::separator:hover,QSplitter::handle:hover{ 105 | background:palette(highlight); 106 | } 107 | QDockWidget::title{ 108 | padding:4px; 109 | background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 110 | border:1px solid rgba(25,25,25,75); 111 | border-bottom:2px solid rgba(25,25,25,75); 112 | } 113 | QDockWidget{ 114 | titlebar-close-icon:url(:/darkstyle/icon_close.png); 115 | titlebar-normal-icon:url(:/darkstyle/icon_restore.png); 116 | } 117 | QDockWidget::close-button,QDockWidget::float-button{ 118 | subcontrol-position:top right; 119 | subcontrol-origin:margin; 120 | position:absolute; 121 | top:3px; 122 | bottom:0px; 123 | width:20px; 124 | height:20px; 125 | } 126 | QDockWidget::close-button{ 127 | right:3px; 128 | } 129 | QDockWidget::float-button{ 130 | right:25px; 131 | } 132 | QGroupBox{ 133 | background-color:rgba(66,66,66,50%); 134 | margin-top:27px; 135 | border:1px solid rgba(25,25,25,127); 136 | border-radius:4px; 137 | } 138 | QGroupBox::title{ 139 | subcontrol-origin:margin; 140 | subcontrol-position:left top; 141 | padding:4px 6px; 142 | margin-left:3px; 143 | background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 144 | border:1px solid rgba(25,25,25,75); 145 | border-bottom:2px solid rgb(127,127,127); 146 | border-top-left-radius:4px; 147 | border-top-right-radius:4px; 148 | } 149 | QTabWidget::pane{ 150 | background-color:rgba(66,66,66,50%); 151 | border-top:1px solid rgba(25,25,25,50%); 152 | } 153 | QTabWidget::tab-bar{ 154 | left:3px; 155 | top:1px; 156 | } 157 | QTabBar{ 158 | background-color:transparent; 159 | qproperty-drawBase:0; 160 | border-bottom:1px solid rgba(25,25,25,50%); 161 | } 162 | QTabBar::tab{ 163 | padding:4px 6px; 164 | background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 165 | border:1px solid rgba(25,25,25,75); 166 | border-top-left-radius:4px; 167 | border-top-right-radius:4px; 168 | } 169 | QTabBar::tab:selected,QTabBar::tab:hover{ 170 | background-color:qlineargradient(x1:0,y1:0,x2:0,y2:1,stop:0 rgba(53,53,53,127),stop:1 rgba(66,66,66,50%)); 171 | border-bottom-color:rgba(66,66,66,75%); 172 | } 173 | QTabBar::tab:selected{ 174 | border-bottom:2px solid palette(highlight); 175 | } 176 | QTabBar::tab::selected:disabled{ 177 | border-bottom:2px solid rgb(127,127,127); 178 | } 179 | QTabBar::tab:!selected{ 180 | margin-top:2px; 181 | } 182 | QCheckBox::indicator{ 183 | width:18px; 184 | height:18px; 185 | } 186 | QCheckBox::indicator:checked,QTreeView::indicator:checked,QTableView::indicator:checked,QGroupBox::indicator:checked{ 187 | image:url(:/darkstyle/icon_checkbox_checked.png); 188 | } 189 | QCheckBox::indicator:checked:pressed,QTreeView::indicator:checked:pressed,QTableView::indicator:checked:pressed,QGroupBox::indicator:checked:pressed{ 190 | image:url(:/darkstyle/icon_checkbox_checked_pressed.png); 191 | } 192 | QCheckBox::indicator:checked:disabled,QTreeView::indicator:checked:disabled,QTableView::indicator:checked:disabled,QGroupBox::indicator:checked:disabled{ 193 | image:url(:/darkstyle/icon_checkbox_checked_disabled.png); 194 | } 195 | QCheckBox::indicator:unchecked,QTreeView::indicator:unchecked,QTableView::indicator:unchecked,QGroupBox::indicator:unchecked{ 196 | image:url(:/darkstyle/icon_checkbox_unchecked.png); 197 | } 198 | QCheckBox::indicator:unchecked:pressed,QTreeView::indicator:unchecked:pressed,QTableView::indicator:unchecked:pressed,QGroupBox::indicator:unchecked:pressed{ 199 | image:url(:/darkstyle/icon_checkbox_unchecked_pressed.png); 200 | } 201 | QCheckBox::indicator:unchecked:disabled,QTreeView::indicator:unchecked:disabled,QTableView::indicator:unchecked:disabled,QGroupBox::indicator:unchecked:disabled{ 202 | image:url(:/darkstyle/icon_checkbox_unchecked_disabled.png); 203 | } 204 | QCheckBox::indicator:indeterminate,QTreeView::indicator:indeterminate,QTableView::indicator:indeterminate,QGroupBox::indicator:indeterminate{ 205 | image:url(:/darkstyle/icon_checkbox_indeterminate.png); 206 | } 207 | QCheckBox::indicator:indeterminate:pressed,QTreeView::indicator:indeterminate:pressed,QTableView::indicator:indeterminate:pressed,QGroupBox::indicator:indeterminate:pressed{ 208 | image:url(:/darkstyle/icon_checkbox_indeterminate_pressed.png); 209 | } 210 | QCheckBox::indicator:indeterminate:disabled,QTreeView::indicator:indeterminate:disabled,QTableView::indicator:indeterminate:disabled,QGroupBox::indicator:indeterminate:disabled{ 211 | image:url(:/darkstyle/icon_checkbox_indeterminate_disabled.png); 212 | } 213 | QRadioButton::indicator{ 214 | width:18px; 215 | height:18px; 216 | } 217 | QRadioButton::indicator:checked{ 218 | image:url(:/darkstyle/icon_radiobutton_checked.png); 219 | } 220 | QRadioButton::indicator:checked:pressed{ 221 | image:url(:/darkstyle/icon_radiobutton_checked_pressed.png); 222 | } 223 | QRadioButton::indicator:checked:disabled{ 224 | image:url(:/darkstyle/icon_radiobutton_checked_disabled.png); 225 | } 226 | QRadioButton::indicator:unchecked{ 227 | image:url(:/darkstyle/icon_radiobutton_unchecked.png); 228 | } 229 | QRadioButton::indicator:unchecked:pressed{ 230 | image:url(:/darkstyle/icon_radiobutton_unchecked_pressed.png); 231 | } 232 | QRadioButton::indicator:unchecked:disabled{ 233 | image:url(:/darkstyle/icon_radiobutton_unchecked_disabled.png); 234 | } 235 | QTreeView, QTableView{ 236 | alternate-background-color:palette(window); 237 | background:palette(base); 238 | } 239 | QTreeView QHeaderView::section, QTableView QHeaderView::section{ 240 | background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(25,25,25,127),stop:1 rgba(53,53,53,75)); 241 | border-style:none; 242 | border-bottom:1px solid palette(dark); 243 | padding-left:5px; 244 | padding-right:5px; 245 | } 246 | QTreeView::item:selected:disabled, QTableView::item:selected:disabled{ 247 | background:rgb(80,80,80); 248 | } 249 | QTreeView::branch{ 250 | background-color:palette(base); 251 | } 252 | QTreeView::branch:has-siblings:!adjoins-item{ 253 | border-image:url(:/darkstyle/icon_vline.png) 0; 254 | } 255 | QTreeView::branch:has-siblings:adjoins-item{ 256 | border-image:url(:/darkstyle/icon_branch_more.png) 0; 257 | } 258 | QTreeView::branch:!has-children:!has-siblings:adjoins-item{ 259 | border-image:url(:/darkstyle/icon_branch_end.png) 0; 260 | } 261 | QTreeView::branch:has-children:!has-siblings:closed, 262 | QTreeView::branch:closed:has-children:has-siblings{ 263 | border-image:none; 264 | image:url(:/darkstyle/icon_branch_closed.png); 265 | } 266 | QTreeView::branch:open:has-children:!has-siblings, 267 | QTreeView::branch:open:has-children:has-siblings{ 268 | border-image:none; 269 | image:url(:/darkstyle/icon_branch_open.png); 270 | } 271 | QScrollBar:vertical{ 272 | background:palette(base); 273 | border-top-right-radius:2px; 274 | border-bottom-right-radius:2px; 275 | width:16px; 276 | margin:0px; 277 | } 278 | QScrollBar::handle:vertical{ 279 | background-color:palette(alternate-base); 280 | border-radius:2px; 281 | min-height:20px; 282 | margin:2px 4px 2px 4px; 283 | } 284 | QScrollBar::handle:vertical:hover{ 285 | background-color:palette(highlight); 286 | } 287 | QScrollBar::add-line:vertical{ 288 | background:none; 289 | height:0px; 290 | subcontrol-position:right; 291 | subcontrol-origin:margin; 292 | } 293 | QScrollBar::sub-line:vertical{ 294 | background:none; 295 | height:0px; 296 | subcontrol-position:left; 297 | subcontrol-origin:margin; 298 | } 299 | QScrollBar:horizontal{ 300 | background:palette(base); 301 | height:16px; 302 | margin:0px; 303 | } 304 | QScrollBar::handle:horizontal{ 305 | background-color:palette(alternate-base); 306 | border-radius:2px; 307 | min-width:20px; 308 | margin:4px 2px 4px 2px; 309 | } 310 | QScrollBar::handle:horizontal:hover{ 311 | background-color:palette(highlight); 312 | } 313 | QScrollBar::add-line:horizontal{ 314 | background:none; 315 | width:0px; 316 | subcontrol-position:bottom; 317 | subcontrol-origin:margin; 318 | } 319 | QScrollBar::sub-line:horizontal{ 320 | background:none; 321 | width:0px; 322 | subcontrol-position:top; 323 | subcontrol-origin:margin; 324 | } 325 | QSlider::handle:horizontal{ 326 | border-radius:4px; 327 | border:1px solid rgba(25,25,25,255); 328 | background-color:palette(alternate-base); 329 | min-height:20px; 330 | margin:0 -4px; 331 | } 332 | QSlider::handle:horizontal:hover{ 333 | background:palette(highlight); 334 | } 335 | QSlider::add-page:horizontal{ 336 | background:palette(base); 337 | } 338 | QSlider::sub-page:horizontal{ 339 | background:palette(highlight); 340 | } 341 | QSlider::sub-page:horizontal:disabled{ 342 | background:rgb(80,80,80); 343 | } 344 | -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_branch_closed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_branch_closed.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_branch_end.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_branch_end.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_branch_more.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_branch_more.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_branch_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_branch_open.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_checkbox_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_checkbox_checked.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_checkbox_checked_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_checkbox_checked_disabled.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_checkbox_checked_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_checkbox_checked_pressed.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_checkbox_indeterminate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_checkbox_indeterminate.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_checkbox_indeterminate_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_checkbox_indeterminate_disabled.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_checkbox_indeterminate_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_checkbox_indeterminate_pressed.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_checkbox_unchecked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_checkbox_unchecked.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_checkbox_unchecked_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_checkbox_unchecked_disabled.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_checkbox_unchecked_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_checkbox_unchecked_pressed.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_close.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_radiobutton_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_radiobutton_checked.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_radiobutton_checked_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_radiobutton_checked_disabled.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_radiobutton_checked_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_radiobutton_checked_pressed.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_radiobutton_unchecked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_radiobutton_unchecked.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_radiobutton_unchecked_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_radiobutton_unchecked_disabled.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_radiobutton_unchecked_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_radiobutton_unchecked_pressed.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_restore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_restore.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_undock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_undock.png -------------------------------------------------------------------------------- /FramelessWindow/darkstyle/icon_vline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/FramelessWindow/darkstyle/icon_vline.png -------------------------------------------------------------------------------- /FramelessWindow/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "FrameLessWidget/framelesswidget.h" 4 | #include "mainwindow.h" 5 | #include "CustomModelView/customheaderview.h" 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QApplication a(argc, argv); 10 | 11 | // 处理默认菜单的英文 12 | QTranslator translator; 13 | translator.load(QString(":/images/qt_zh_CN.qm")); 14 | QApplication::installTranslator(&translator); 15 | 16 | // 显示最大化和全屏 17 | FramelessWidget w; 18 | // 隐藏最大化和全屏 19 | // FramelessWidget w(false, false); 20 | // 显示最大化,关闭全屏 21 | // FramelessWidget w(true, false); 22 | // 隐藏最大化, 显示全屏, 这种情况应该无法打开全屏 23 | // FramelessWidget w(false, true); 24 | auto pMain = new MainWindow(&w); 25 | w.setContent(pMain); 26 | w.show(); 27 | 28 | return a.exec(); 29 | } 30 | -------------------------------------------------------------------------------- /FramelessWindow/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "mainwindow.h" 5 | #include "ui_mainwindow.h" 6 | #include "CustomModelView/customlineeditedelegate.h" 7 | 8 | MainWindow::MainWindow(QWidget *parent) : 9 | QMainWindow(parent), 10 | ui(new Ui::MainWindow), 11 | m_pBtnGroupLeftNav(new QButtonGroup(this)), 12 | m_pVersionWidget(new VersionInfoWidget("版本号: V1.0.0")), 13 | m_pCustomTableView(new CustomTableView()), 14 | m_pListView(new QListView()), 15 | m_pTreeView(new QTreeView()), 16 | m_pBasicWidget(new BasicWidget(this)) 17 | { 18 | // 框架 --start 19 | ui->setupUi(this); 20 | this->initUi(); 21 | this->initConnetion(); 22 | // 框架 --end 23 | } 24 | 25 | MainWindow::~MainWindow() 26 | { 27 | delete ui; 28 | } 29 | 30 | void MainWindow::initUi() 31 | { 32 | // 框架 --start 33 | // 初始侧边导航为100px, 导航和内容的比例为 1 : 9 34 | QList splitterList{100, this->width() - 108}; 35 | ui->splitter->setSizes(splitterList); 36 | ui->splitter->setStretchFactor(0, 1); 37 | ui->splitter->setStretchFactor(1, 9); 38 | ui->statusbar->addPermanentWidget(m_pVersionWidget); 39 | for(auto pComboBox: findChildren()){ 40 | pComboBox->setView(new QListView()); 41 | } 42 | // 框架 --end 43 | 44 | // 测试 --start 45 | this->addNavStackWidget("", tr("基本组件"), m_pBasicWidget); 46 | this->addNavHLine(); 47 | 48 | auto tableWidget = new QWidget(this); 49 | tableWidget->setLayout(new QHBoxLayout); 50 | tableWidget->layout()->addWidget(m_pCustomTableView); 51 | tableWidget->setObjectName("tableWidget"); 52 | this->addNavStackWidget("tableBtn", "tableView", tableWidget); 53 | 54 | auto listWidget = new QWidget(this); 55 | listWidget->setLayout(new QHBoxLayout); 56 | listWidget->layout()->addWidget(m_pListView); 57 | listWidget->setObjectName("listWidget"); 58 | this->addNavStackWidget("listBtn", "listView", listWidget); 59 | 60 | auto treeWidget = new QWidget(this); 61 | treeWidget->setLayout(new QHBoxLayout); 62 | treeWidget->layout()->addWidget(m_pTreeView); 63 | treeWidget->setObjectName("treeWidget"); 64 | this->addNavStackWidget("treeBtn", "treeView", treeWidget); 65 | 66 | this->addNavHLine(); 67 | this->addNavStackWidget("", tr("自绘"), new QWidget(this), QIcon(":/images/filter.png")); 68 | 69 | m_pListView->setModel(&m_model); 70 | m_pTreeView->setModel(&m_model); 71 | 72 | m_pCustomTableView->setModel(&m_model); 73 | m_pCustomTableView->setColumnWidth(1, 150); 74 | 75 | // 初始化菜单 76 | m_pToListView = new QAction(tr("转到ListView"), this); 77 | m_pToTreeView = new QAction(tr("转到TreeView"), this); 78 | m_pToTableView = new QAction(tr("转到TableView"), this); 79 | m_pViewMenu = new QMenu(this); 80 | m_pViewMenu->addAction(m_pToListView); 81 | m_pViewMenu->addAction(m_pToTreeView); 82 | m_pViewMenu->addAction(m_pToTableView); 83 | m_viewBtnMap[m_pToTableView] = "tableBtn"; 84 | m_viewBtnMap[m_pToListView] = "listBtn"; 85 | m_viewBtnMap[m_pToTreeView] = "treeBtn"; 86 | m_pCustomTableView->setContextMenuPolicy(Qt::CustomContextMenu); 87 | m_pTreeView->setContextMenuPolicy(Qt::CustomContextMenu); 88 | m_pListView->setContextMenuPolicy(Qt::CustomContextMenu); 89 | // 测试 --end 90 | } 91 | 92 | void MainWindow::initConnetion() 93 | { 94 | // 框架 --start 95 | connect(m_pBtnGroupLeftNav, SIGNAL(buttonClicked(QAbstractButton *)), 96 | this, SLOT(on_buttonClickedLeftNav(QAbstractButton *))); 97 | // 框架 --end 98 | 99 | // 测试 --start 100 | connect(m_pCustomTableView, &CustomTableView::customContextMenuRequested, this, [this](const QPoint &){ 101 | m_pToTableView->setEnabled(false); 102 | m_pToListView->setEnabled(true); 103 | m_pToTreeView->setEnabled(true); 104 | m_pViewMenu->exec(QCursor::pos()); 105 | }); 106 | connect(m_pListView, &QListView::customContextMenuRequested, this, [this](const QPoint &){ 107 | m_pToTableView->setEnabled(true); 108 | m_pToListView->setEnabled(false); 109 | m_pToTreeView->setEnabled(true); 110 | m_pViewMenu->exec(QCursor::pos()); 111 | }); 112 | connect(m_pTreeView, &QTreeView::customContextMenuRequested, this, [this](const QPoint &){ 113 | m_pToTableView->setEnabled(true); 114 | m_pToListView->setEnabled(true); 115 | m_pToTreeView->setEnabled(false); 116 | m_pViewMenu->exec(QCursor::pos()); 117 | }); 118 | connect(m_pToListView, &QAction::triggered, this, [this](){ 119 | auto view = qApp->focusWidget(); 120 | auto who = m_viewBtnMap.value(m_pToListView, ""); 121 | auto btn = findChild(who); 122 | btn->click(); 123 | if(view == m_pCustomTableView){ 124 | int row = m_pCustomTableView->currentIndex().row(); 125 | auto index = m_pListView->model()->index(row, 0); 126 | m_pListView->setCurrentIndex(index); 127 | }else if(view == m_pTreeView){ 128 | int row = m_pTreeView->currentIndex().row(); 129 | auto index = m_pListView->model()->index(row, 0); 130 | m_pListView->setCurrentIndex(index); 131 | } 132 | }); 133 | connect(m_pToTreeView, &QAction::triggered, this, [this](){ 134 | auto view = qApp->focusWidget(); 135 | auto who = m_viewBtnMap.value(m_pToTreeView, ""); 136 | auto btn = findChild(who); 137 | btn->click(); 138 | if(view == m_pCustomTableView){ 139 | int row = m_pCustomTableView->currentIndex().row(); 140 | auto index = m_pTreeView->model()->index(row, 0); 141 | m_pTreeView->setCurrentIndex(index); 142 | }else if(view == m_pListView){ 143 | int row = m_pListView->currentIndex().row(); 144 | auto index = m_pTreeView->model()->index(row, 0); 145 | m_pTreeView->setCurrentIndex(index); 146 | } 147 | }); 148 | connect(m_pToTableView, &QAction::triggered, this, [this](){ 149 | auto view = qApp->focusWidget(); 150 | auto who = m_viewBtnMap.value(m_pToTableView, ""); 151 | auto btn = findChild(who); 152 | btn->click(); 153 | if(view == m_pTreeView){ 154 | int row = m_pTreeView->currentIndex().row(); 155 | auto index = m_pCustomTableView->model()->index(row, 0); 156 | m_pCustomTableView->setCurrentIndex(index); 157 | }else if(view == m_pListView){ 158 | int row = m_pListView->currentIndex().row(); 159 | auto index = m_pCustomTableView->model()->index(row, 0); 160 | m_pCustomTableView->setCurrentIndex(index); 161 | } 162 | }); 163 | // 测试 --end 164 | } 165 | 166 | void MainWindow::on_buttonClickedLeftNav(QAbstractButton *btn) 167 | { 168 | ui->stackedWidget->setCurrentIndex(m_pBtnGroupLeftNav->id(btn)); 169 | QToolButton *obj = qobject_cast(btn); 170 | obj->setChecked(true); 171 | } 172 | 173 | void MainWindow::addNavStackWidget(QString objectName, QString text, QWidget *widget, QIcon ico) 174 | { 175 | int btnId = m_pTBtnLeftNavVector.length(); 176 | auto pTBtn = new QToolButton(this); 177 | m_pTBtnLeftNavVector.append(pTBtn); 178 | pTBtn->setText(text); 179 | pTBtn->setCheckable(true); 180 | pTBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); 181 | if(!objectName.trimmed().isEmpty()){ 182 | pTBtn->setObjectName(objectName); 183 | } 184 | if(!ico.isNull()){ 185 | pTBtn->setIcon(ico); 186 | pTBtn->setIconSize(QSize(16, 16)); 187 | pTBtn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); 188 | }else{ 189 | pTBtn->setToolButtonStyle(Qt::ToolButtonTextOnly); 190 | } 191 | m_pBtnGroupLeftNav->addButton(pTBtn, btnId); 192 | ui->verticalLayout_left_nav->addWidget(pTBtn); 193 | ui->stackedWidget->addWidget(widget); 194 | } 195 | 196 | void MainWindow::addNavHLine() 197 | { 198 | QFrame *line = new QFrame(this); 199 | line->setGeometry(QRect(40, 180, 400, 3)); 200 | line->setFrameShape(QFrame::HLine); 201 | line->setFrameShadow(QFrame::Sunken); 202 | line->raise(); 203 | line->setObjectName("HLine"); 204 | ui->verticalLayout_left_nav->addWidget(line); 205 | } 206 | -------------------------------------------------------------------------------- /FramelessWindow/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "CustomModelView/custommodel.h" 12 | #include "CustomModelView/customlistview.h" 13 | #include "CustomModelView/customtableview.h" 14 | #include "CustomModelView/customtreeview.h" 15 | #include "basicwidget.h" 16 | 17 | namespace Ui { 18 | class MainWindow; 19 | } 20 | 21 | class VersionInfoWidget : public QWidget 22 | { 23 | Q_OBJECT 24 | public: 25 | explicit VersionInfoWidget(QString version="V1.0.0", QWidget *parent = nullptr) 26 | : QWidget(parent){ 27 | this->setObjectName("customStatusBar"); 28 | QHBoxLayout *hLayout = new QHBoxLayout; 29 | QLabel *label = new QLabel(version, this); 30 | hLayout->addWidget(label); 31 | hLayout->setContentsMargins(0, 0, 0, 0); 32 | this->setLayout(hLayout); 33 | this->setStyleSheet("#customStatusBar QLabel{color: #FFFFFF;}"); 34 | } 35 | }; 36 | 37 | 38 | 39 | class MainWindow : public QMainWindow 40 | { 41 | Q_OBJECT 42 | 43 | public: 44 | // 框架 --start 45 | explicit MainWindow(QWidget *parent = nullptr); 46 | ~MainWindow(); 47 | 48 | void initConnetion(); 49 | void initUi(); 50 | 51 | /* 添加自定义的页面到QStackWidget中,并添加左导航栏按钮 52 | * @name: 左导航按钮需要显示的名字 53 | * @widget: 需要插入的页面 54 | */ 55 | void addNavStackWidget(QString objectName, QString text, QWidget *widget, QIcon ico=QIcon()); 56 | // 向导航栏中添加水平分割线 57 | void addNavHLine(); 58 | // 框架 --end 59 | 60 | private slots: 61 | // 框架 --start 62 | void on_buttonClickedLeftNav(QAbstractButton *btn); 63 | // 框架 --end 64 | 65 | private: 66 | // 框架 --start 67 | Ui::MainWindow *ui; 68 | QButtonGroup *m_pBtnGroupLeftNav; 69 | QVector m_pTBtnLeftNavVector; 70 | VersionInfoWidget *m_pVersionWidget; 71 | // 框架 --end 72 | 73 | CustomModel m_model; 74 | CustomTableView *m_pCustomTableView; 75 | QListView *m_pListView; 76 | QTreeView *m_pTreeView; 77 | 78 | // 菜单跳转 79 | QAction *m_pToListView; 80 | QAction *m_pToTreeView; 81 | QAction *m_pToTableView; 82 | QMenu *m_pViewMenu; 83 | QMap m_viewBtnMap; 84 | 85 | BasicWidget *m_pBasicWidget; 86 | }; 87 | 88 | #endif // MAINWINDOW_H 89 | -------------------------------------------------------------------------------- /FramelessWindow/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 711 10 | 435 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | /* 左导航栏 */ 18 | #widget_left_nav{ 19 | background-color: #ddedfa; 20 | } 21 | #widget_left_nav QToolButton{ 22 | color: #000000; 23 | background-color: none; 24 | border:none; 25 | padding: 2px 2px 2px 2px; 26 | min-height: 0px; 27 | border-radius:0px; 28 | } 29 | #widget_left_nav QToolButton:checked{ 30 | color: #3096f8; 31 | } 32 | #widget_left_nav QToolButton:hover{ 33 | color: #ffffff; 34 | background-color: #2e9eea; 35 | } 36 | 37 | /* 分割线 */ 38 | #widget_left_nav #HLine{ 39 | background-color: #ddedfa; 40 | border-top: 1px solid #a0a0a0; 41 | } 42 | 43 | #CustomHorizontalHeaderView::section:horizontal{ 44 | border: none; 45 | padding-left:5px; 46 | padding-right:5px; 47 | color: rgb(255, 255, 255); 48 | } 49 | 50 | #CustomHorizontalHeaderView::section:!last{ 51 | border-right: 1px solid rgb(230, 230, 230); 52 | } 53 | #CustomTableView{ 54 | alternate-background-color: rgb(242,242,242); 55 | background-color: rgb(255,255,255); 56 | selection-background-color: #0078D7; 57 | selection-color: #FAFAFA; 58 | gridline-color: rgb(230, 230, 230); 59 | border-top: none; 60 | border-right: 1px solid rgb(230, 230, 230); 61 | border-left: 1px solid rgb(230, 230, 230); 62 | border-bottom: 1px solid rgb(230, 230, 230); 63 | } 64 | #CustomHeaderView #widget_header{ 65 | background-color:qlineargradient(x1:0,y1:1,x2:0,y2:0,stop:0 rgba(17,127,225, 1),stop:1 rgba(48,150,248, 0.5));; 66 | border-right: 1px solid rgb(230, 230, 230); 67 | } 68 | #CustomHeaderView #widget_header QLabel{ 69 | color: rgb(255, 255, 255); 70 | } 71 | #CustomHeaderView #widget_header QToolButton{ 72 | background-color:none; 73 | border:none; 74 | } 75 | #CustomHeaderView #widget_header QToolButton:hover{ 76 | background-color: #2e9eea; 77 | } 78 | #CustomHeaderView #widget_header QToolButton:pressed{ 79 | background-color:palette(highlight); 80 | } 81 | #CustomHeaderView #widget_header QToolButton:checked{ 82 | background-color: #C2C2C2; 83 | } 84 | #CustomHeaderView QToolButton{ 85 | min-height: 0px; 86 | border-radius:0px; 87 | padding:0px; 88 | background-color: transparent; 89 | } 90 | 91 | 92 | 93 | 94 | 0 95 | 96 | 97 | 0 98 | 99 | 100 | 0 101 | 102 | 103 | 0 104 | 105 | 106 | 0 107 | 108 | 109 | 110 | 111 | QFrame::NoFrame 112 | 113 | 114 | QFrame::Plain 115 | 116 | 117 | 0 118 | 119 | 120 | Qt::Horizontal 121 | 122 | 123 | 124 | 125 | 0 126 | 0 127 | 128 | 129 | 130 | 131 | 50 132 | 0 133 | 134 | 135 | 136 | 137 | 150 138 | 16777215 139 | 140 | 141 | 142 | -1 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | Qt::Vertical 152 | 153 | 154 | 155 | 20 156 | 247 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FramelessWindow 2 | Qt Frameless Widget; 基于Qt框架的自定义窗口框架; 参考[Qt-Frameless-Window-DarkStyle](https://github.com/Jorgen-VikingGod/Qt-Frameless-Window-DarkStyle) 3 | 4 | ## 演示效果 5 | 6 | 7 | ![home](https://github.com/BeiChenYx/FramelessWindow/blob/master/doc/home.png) 8 | 9 | ![images](https://github.com/BeiChenYx/FramelessWindow/blob/master/doc/chart.gif) 10 | 11 | 修复Qt-Frameless-Window-DarkStyle Bug, 及更改的内容: 12 | 1. 增加了Qt5的支持; 13 | 2. 修复移动窗口到最小的时候仍然可以继续移动窗口的问题; 14 | 3. 简化了一部分代码; 15 | 4. 去除了虚拟桌面,多桌面的支持; 16 | 5. 增加了全屏窗口的支持; 17 | 6. 增加了自定义QHeaderView功能,实现在表头增加过来和排序; 18 | 19 | 20 | 21 | ## Licence 22 | > The MIT License 23 | > 24 | > Copyright (c) 2020, yangxing (https://github.com/BeiChenYx, yangxing2297@163.com) 25 | -------------------------------------------------------------------------------- /Untitled Diagram.drawio: -------------------------------------------------------------------------------- 1 | UzV2zq1wL0osyPDNT0nNUTV2VTV2LsrPL4GwciucU3NyVI0MMlNUjV1UjYwMgFjVyA2HrCFY1qAgsSg1rwSLBiADYTaQg2Y1AA== -------------------------------------------------------------------------------- /doc/chart.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/doc/chart.gif -------------------------------------------------------------------------------- /doc/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeiChenYx/FramelessWindow/2ae1d8c6453ab0c9f1e7760d04add429af0b1404/doc/home.png --------------------------------------------------------------------------------