Debian Codegraph @

kysdk-qtwidgets/test/testKPushButton/widget.cpp

raw
1 /*
2 *
3 *
4 * Copyright (C) 2023, KylinSoft Co., Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this library. If not, see <https://www.gnu.org/licenses/>.
18 *
19 * Authors: Xiangwei Liu <[email protected]>
20 *
21 */
22
23 #include "widget.h"
24 #include "kpushbutton.h"
25 #include <QDebug>
26 #include <QHBoxLayout>
27 #include <QVBoxLayout>
28
29 using namespace kdk;
30
31 Widget::Widget(QWidget *parent)
32 : QWidget(parent)
33 {
34 QHBoxLayout *layout1 = new QHBoxLayout(); /*半透明字体按钮布局,包括按钮1、2、3*/
35
36 KPushButton *btn1 = new KPushButton(this); /*不可用透明按钮*/
37 btn1->setText("button1");
38 btn1->setTranslucent(true);
39 btn1->setEnabled(false);
40
41 KPushButton *btn2 = new KPushButton(this); /*可用透明按钮*/
42 btn2->setText("button2");
43 btn2->setTranslucent(true);
44 btn2->setBackgroundColor(Qt::blue);
45
46 KPushButton *btn3 = new KPushButton(this); /*圆形透明按钮,如果需要设置为正圆需要自己设置大小,默认跟随layout*/
47 btn3->setText("button3");
48 btn3->setTranslucent(true);
49 btn3->setButtonType(KPushButton::CircleType);
50
51 layout1->addWidget(btn1);
52 layout1->addWidget(btn2);
53 layout1->addWidget(btn3);
54
55 QHBoxLayout *layout2 = new QHBoxLayout(); /*半透明图标按钮,包括按钮4、5*/
56
57 KPushButton *btn4 = new KPushButton(this);
58 btn4->setIcon(QIcon::fromTheme("go-previous-symbolic"));
59 btn4->setTranslucent(true);
60 btn4->setFixedSize(32, 32);
61 btn4->setIconSize(QSize(24, 24));
62 btn4->setBackgroundColor(Qt::blue);
63 KPushButton *btn5 = new KPushButton(this);
64 btn5->setIcon(QIcon::fromTheme("go-next-symbolic"));
65 btn5->setTranslucent(true);
66 btn5->setFixedSize(32, 32);
67 btn5->setIconSize(QSize(24, 24));
68
69 layout2->addWidget(btn4);
70 layout2->addWidget(btn5);
71
72 QHBoxLayout *layout3 = new QHBoxLayout(); /*正常带图标不透明按钮,包括6、7*/
73 KPushButton *btn6 = new KPushButton(this);
74 btn6->setIcon(QIcon::fromTheme("go-previous-symbolic"));
75 btn6->setFixedSize(32, 32);
76 btn6->setIconSize(QSize(24, 24));
77 btn6->setIconHighlight(true);
78 btn6->setBackgroundColor(Qt::transparent);
79
80 KPushButton *btn7 = new KPushButton(this);
81 btn7->setIcon(QIcon::fromTheme("go-next-symbolic"));
82 btn7->setFixedSize(32, 32);
83 btn7->setIconSize(QSize(24, 24));
84 btn7->setIconHighlight(true);
85 btn7->setBackgroundColor(Qt::transparent);
86
87 layout3->addWidget(btn6);
88 layout3->addWidget(btn7);
89
90 QHBoxLayout *layout4 = new QHBoxLayout();
91
92 KPushButton *btn8 = new KPushButton(this); /*设置文字且设置圆角的不透明按钮*/
93 btn8->setText("button8");
94 btn8->setBorderRadius(10);
95
96 KPushButton *btn9 = new KPushButton(this); /*设置图标且设置圆角的不透明按钮*/
97 btn9->setIcon(QIcon::fromTheme("list-add-symbolic"));
98 btn9->setIconColor(Qt::white);
99 btn9->setBackgroundColorHighlight(true); /*设置按钮背景色跟随系统高亮色*/
100 // btn9->setBackgroundColor(Qt::red); /*用户设置自定义背景色(与跟随系统高亮存在先后关系,后设置的生效)*/
101
102 btn9->setFixedSize(40, 40);
103 btn9->setBorderRadius(20);
104 btn9->setIconSize(QSize(24, 24));
105
106 layout4->addWidget(btn8);
107 layout4->addWidget(btn9);
108
109 QVBoxLayout *layout = new QVBoxLayout(this);
110 layout->addLayout(layout1);
111 layout->addLayout(layout2);
112 layout->addLayout(layout3);
113 layout->addLayout(layout4);
114
115 this->setLayout(layout);
116 }
117
118 Widget::~Widget()
119 {
120 }
121
122 void Widget::onButtonClicked()
123 {
124 qDebug() << "clicked";
125 }