├── .gitignore ├── LICENSE ├── Qt-InterestingIndicate.pro ├── README.md ├── interestingindicate.cpp ├── interestingindicate.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── screenshot.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # This file is used to ignore files which are generated 2 | # ---------------------------------------------------------------------------- 3 | 4 | *~ 5 | *.autosave 6 | *.a 7 | *.core 8 | *.moc 9 | *.o 10 | *.obj 11 | *.orig 12 | *.rej 13 | *.so 14 | *.so.* 15 | *_pch.h.cpp 16 | *_resource.rc 17 | *.qm 18 | .#* 19 | *.*# 20 | core 21 | !core/ 22 | tags 23 | .DS_Store 24 | .directory 25 | *.debug 26 | Makefile* 27 | *.prl 28 | *.app 29 | moc_*.cpp 30 | ui_*.h 31 | qrc_*.cpp 32 | Thumbs.db 33 | *.res 34 | *.rc 35 | /.qmake.cache 36 | /.qmake.stash 37 | 38 | # qtcreator generated files 39 | *.pro.user* 40 | 41 | # xemacs temporary files 42 | *.flc 43 | 44 | # Vim temporary files 45 | .*.swp 46 | 47 | # Visual Studio generated files 48 | *.ib_pdb_index 49 | *.idb 50 | *.ilk 51 | *.pdb 52 | *.sln 53 | *.suo 54 | *.vcproj 55 | *vcproj.*.*.user 56 | *.ncb 57 | *.sdf 58 | *.opensdf 59 | *.vcxproj 60 | *vcxproj.* 61 | 62 | # MinGW generated files 63 | *.Debug 64 | *.Release 65 | 66 | # Python byte code 67 | *.pyc 68 | 69 | # Binaries 70 | # -------- 71 | *.dll 72 | *.exe 73 | 74 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Qt-InterestingIndicate.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | interestingindicate.cpp \ 20 | main.cpp \ 21 | mainwindow.cpp 22 | 23 | HEADERS += \ 24 | interestingindicate.h \ 25 | mainwindow.h 26 | 27 | FORMS += \ 28 | mainwindow.ui 29 | 30 | # Default rules for deployment. 31 | qnx: target.path = /tmp/$${TARGET}/bin 32 | else: unix:!android: target.path = /opt/$${TARGET}/bin 33 | !isEmpty(target.path): INSTALLS += target 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 有趣的指示条 2 | === 3 | 4 | 一个带动画的三角形箭头,如图: 5 | 6 | ![截图](screenshot.gif) 7 | 8 | 9 | 10 | ## 用法 11 | 12 | `interestingindicate.h` `interestingindicate.cpp` 放到工程中,直接使用即可。 13 | 14 | 注意:建议**绝对布局**,手动指定 widget 的边界,上下(第一项top和最后一项bottom,不包括spacing),左边(全部项的最左边-指示条宽度)。 -------------------------------------------------------------------------------- /interestingindicate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "interestingindicate.h" 6 | 7 | InterestingIndicate::InterestingIndicate(QWidget *parent) : QWidget(parent) 8 | { 9 | setTriangleSize(16); 10 | srand(static_cast(time(nullptr))); 11 | } 12 | 13 | void InterestingIndicate::setTopAndBottom(QWidget *top, QWidget *bottom) 14 | { 15 | setGeometry(top->pos().x() - triangleSize, top->geometry().top(), triangleSize, 16 | bottom->geometry().bottom() - top->geometry().top()); 17 | } 18 | 19 | void InterestingIndicate::setTriangleSize(int size) 20 | { 21 | this->triangleSize = size; 22 | this->setFixedWidth(static_cast(size * 1.732 / 2 + 0.5)); 23 | } 24 | 25 | void InterestingIndicate::setColor(QColor c) 26 | { 27 | this->lineColor = c; 28 | update(); 29 | } 30 | 31 | void InterestingIndicate::setTotalCount(int count) 32 | { 33 | this->totalCount = count; 34 | } 35 | 36 | void InterestingIndicate::setItemSpacing(int spacing) 37 | { 38 | this->itemSpacing = spacing; 39 | } 40 | 41 | void InterestingIndicate::setCurrentIndex(int index) 42 | { 43 | this->currentIndex = index; 44 | setCenterY(getCenterYByIndex(index)); 45 | update(); 46 | } 47 | 48 | void InterestingIndicate::moveIndicate(int index) 49 | { 50 | this->currentIndex = index; 51 | int y = getCenterYByIndex(index); 52 | const bool down = currentY > y; 53 | const int distance = qAbs(currentY - y); 54 | if (distance <= 0) // 不需要移动 55 | { 56 | // TODO: 来一个有意思的动画? 57 | return ; 58 | } 59 | this->currentY = y; 60 | 61 | const int baseTime = 150 + 350 * distance / height(); 62 | const int deltaTime = 100; 63 | 64 | // 开启随机动画 65 | aniPV = 3; 66 | QPropertyAnimation* ani = new QPropertyAnimation(this, "line1"); 67 | ani->setStartValue(line1); 68 | ani->setEndValue(getLineTopByCenterY(y, TL_Left)); 69 | ani->setDuration(baseTime); 70 | ani->setEasingCurve(QEasingCurve::InOutCubic); 71 | ani->start(); 72 | connect(ani, &QPropertyAnimation::valueChanged, this, [=]{ 73 | update(); 74 | }); 75 | connect(ani, SIGNAL(finished()), ani, SLOT(deleteLater())); 76 | connect(ani, &QPropertyAnimation::finished, this, [=]{ 77 | aniPV--; 78 | update(); 79 | }); 80 | 81 | 82 | ani = new QPropertyAnimation(this, "line2"); 83 | ani->setStartValue(line2); 84 | ani->setEndValue(getLineTopByCenterY(y, TL_TopRight)); 85 | ani->setDuration(baseTime + deltaTime * (down ? 1 : 2)); 86 | ani->setEasingCurve(QEasingCurve::InOutCubic); 87 | ani->start(); 88 | connect(ani, &QPropertyAnimation::valueChanged, this, [=]{ 89 | update(); 90 | }); 91 | connect(ani, SIGNAL(finished()), ani, SLOT(deleteLater())); 92 | connect(ani, &QPropertyAnimation::finished, this, [=]{ 93 | aniPV--; 94 | update(); 95 | }); 96 | 97 | ani = new QPropertyAnimation(this, "line3"); 98 | ani->setStartValue(line3); 99 | ani->setEndValue(getLineTopByCenterY(y, TL_BottomRight)); 100 | ani->setDuration(baseTime + deltaTime * (down ? 2 : 1)); 101 | ani->setEasingCurve(QEasingCurve::InOutCubic); 102 | ani->start(); 103 | connect(ani, &QPropertyAnimation::valueChanged, this, [=]{ 104 | update(); 105 | }); 106 | connect(ani, SIGNAL(finished()), ani, SLOT(deleteLater())); 107 | connect(ani, &QPropertyAnimation::finished, this, [=]{ 108 | aniPV--; 109 | update(); 110 | }); 111 | } 112 | 113 | int InterestingIndicate::currentIndicateIndex() const 114 | { 115 | return currentIndex; 116 | } 117 | 118 | void InterestingIndicate::paintEvent(QPaintEvent *) 119 | { 120 | QPainter painter(this); 121 | painter.setRenderHint(QPainter::Antialiasing, true); 122 | painter.setPen(QPen(lineColor, 1)); 123 | const int border = 1; 124 | double halfLine = 0.5; 125 | 126 | if (!aniPV) // 线两端重合的点不好看,还是一口气画完吧! 127 | { 128 | QPainterPath path; 129 | path.moveTo(border, line1); 130 | path.lineTo(border, line1 + triangleSize); 131 | path.lineTo(width()-border, line3); 132 | path.lineTo(border, line2); 133 | painter.drawPath(path); 134 | } 135 | else // 运动中,挨个画每一条线 136 | { 137 | painter.drawLine(QPointF(border, line1+halfLine), QPointF(border, line1 + triangleSize-halfLine)); 138 | painter.drawLine(QPointF(border, line2), QPointF(width()-border-halfLine, line2 + triangleSize/2-halfLine)); 139 | painter.drawLine(QPointF(width()-border-halfLine, line3+halfLine), QPointF(border, line3 + triangleSize/2)); 140 | } 141 | } 142 | 143 | int InterestingIndicate::getCenterYByIndex(int index) 144 | { 145 | if (totalCount == 0) 146 | return 0; 147 | double everyHeight = static_cast(height() - itemSpacing * (totalCount - 1)) / totalCount; 148 | if (everyHeight <= 0) // 数据不正常 149 | return 0; 150 | 151 | return static_cast((everyHeight + itemSpacing) * index + everyHeight / 2); 152 | } 153 | 154 | int InterestingIndicate::getLineTopByCenterY(int centerY, TriangleLIne line) 155 | { 156 | switch (line) 157 | { 158 | case TL_Left: 159 | return centerY - triangleSize/2; 160 | case TL_TopRight: 161 | return centerY - triangleSize/2; 162 | case TL_BottomRight: 163 | return centerY; 164 | } 165 | } 166 | 167 | void InterestingIndicate::setCenterY(int y) 168 | { 169 | this->currentY = y; 170 | line1 = getLineTopByCenterY(y, TL_Left); 171 | line2 = getLineTopByCenterY(y, TL_TopRight); 172 | line3 = getLineTopByCenterY(y, TL_BottomRight); 173 | update(); 174 | } 175 | 176 | int InterestingIndicate::getLine1() 177 | { 178 | return line1; 179 | } 180 | 181 | void InterestingIndicate::setLine1(int x) 182 | { 183 | this->line1 = x; 184 | } 185 | 186 | int InterestingIndicate::getLine2() 187 | { 188 | return line2; 189 | } 190 | 191 | void InterestingIndicate::setLine2(int x) 192 | { 193 | this->line2 = x; 194 | } 195 | 196 | int InterestingIndicate::getLine3() 197 | { 198 | return line3; 199 | } 200 | 201 | void InterestingIndicate::setLine3(int x) 202 | { 203 | this->line3 = x; 204 | } 205 | -------------------------------------------------------------------------------- /interestingindicate.h: -------------------------------------------------------------------------------- 1 | #ifndef INTERESTINGINDICATE_H 2 | #define INTERESTINGINDICATE_H 3 | 4 | #include 5 | #include 6 | 7 | class InterestingIndicate : public QWidget 8 | { 9 | Q_OBJECT 10 | Q_PROPERTY(int line1 READ getLine1 WRITE setLine1) 11 | Q_PROPERTY(int line2 READ getLine2 WRITE setLine2) 12 | Q_PROPERTY(int line3 READ getLine3 WRITE setLine3) 13 | public: 14 | InterestingIndicate(QWidget *parent = nullptr); 15 | 16 | enum TriangleLIne 17 | { 18 | TL_Left, 19 | TL_TopRight, 20 | TL_BottomRight 21 | }; 22 | 23 | /// 根据控件调整自己的位置 24 | void setTopAndBottom(QWidget* top, QWidget* bottom); 25 | 26 | /// 设置三角形边长的尺寸 27 | void setTriangleSize(int size); 28 | 29 | /// 设置绘制的颜色 30 | void setColor(QColor c); 31 | 32 | /// 设置总数量 33 | void setTotalCount(int count); 34 | 35 | /// 设置每两个项目之间的spacing(不包括上下两边外面的) 36 | void setItemSpacing(int spacing); 37 | 38 | /// 设置索引(不用动画) 39 | void setCurrentIndex(int index); 40 | 41 | /// 设置缩影(带动画的) 42 | void moveIndicate(int index); 43 | 44 | /// 当前指向的索引 45 | int currentIndicateIndex() const; 46 | 47 | protected: 48 | void paintEvent(QPaintEvent *) override; 49 | 50 | signals: 51 | 52 | public slots: 53 | 54 | private: 55 | /// 获取某一个index的中心点Y坐标 56 | int getCenterYByIndex(int index); 57 | /// 根据中间点,获取线绘制的Y 58 | int getLineTopByCenterY(int centerY, TriangleLIne line); 59 | /// 设置指示条的中心点Y 60 | void setCenterY(int y); 61 | 62 | private: 63 | int getLine1(); 64 | void setLine1(int x); 65 | int getLine2(); 66 | void setLine2(int x); 67 | int getLine3(); 68 | void setLine3(int x); 69 | 70 | int line1 = 0; 71 | int line2 = 0; 72 | int line3 = 0; 73 | 74 | private: 75 | int triangleSize = 16; 76 | QColor lineColor = Qt::black; 77 | int totalCount = 0; 78 | int itemSpacing = 0; 79 | int currentIndex = -1; 80 | int currentY = -1; 81 | int aniPV = 0; 82 | }; 83 | 84 | #endif // INTERESTINGINDICATE_H 85 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | MainWindow w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) 5 | : QMainWindow(parent) 6 | , ui(new Ui::MainWindow) 7 | { 8 | ui->setupUi(this); 9 | 10 | ui->widget->setTriangleSize(16); 11 | ui->widget->setTotalCount(5); 12 | } 13 | 14 | MainWindow::~MainWindow() 15 | { 16 | delete ui; 17 | } 18 | 19 | void MainWindow::showEvent(QShowEvent *event) 20 | { 21 | QMainWindow::showEvent(event); 22 | ui->widget->setCurrentIndex(0); 23 | } 24 | 25 | 26 | void MainWindow::on_pushButton_clicked() 27 | { 28 | int r = ui->widget->currentIndicateIndex(); 29 | while (r == ui->widget->currentIndicateIndex()) 30 | r = qrand() % 5; 31 | ui->widget->moveIndicate(r); 32 | } 33 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class MainWindow; } 8 | QT_END_NAMESPACE 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | MainWindow(QWidget *parent = nullptr); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void showEvent(QShowEvent* event); 20 | void on_pushButton_clicked(); 21 | 22 | private: 23 | Ui::MainWindow *ui; 24 | }; 25 | #endif // MAINWINDOW_H 26 | -------------------------------------------------------------------------------- /mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 227 10 | 341 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 60 21 | 40 22 | 41 23 | 231 24 | 25 | 26 | 27 | 28 | 29 | 30 | 130 31 | 120 32 | 75 33 | 23 34 | 35 | 36 | 37 | move 38 | 39 | 40 | 41 | 42 | 43 | 44 | 0 45 | 0 46 | 227 47 | 23 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | InterestingIndicate 56 | QWidget 57 |
interestingindicate.h
58 | 1 59 |
60 |
61 | 62 | 63 |
64 | -------------------------------------------------------------------------------- /screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iwxyi/Qt-InterestingIndicate/11d0f6b5a0045e94ce754e93576f3dc2e20ab585/screenshot.gif --------------------------------------------------------------------------------