| 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: Zhen Sun <[email protected]> |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "widget.h" |
| 24 |
#include "kcolorbutton.h" |
| 25 |
#include <QButtonGroup> |
| 26 |
#include <QDebug> |
| 27 |
#include <QHBoxLayout> |
| 28 |
|
| 29 |
using namespace kdk; |
| 30 |
|
| 31 |
Widget::Widget(QWidget *parent) |
| 32 |
: QWidget(parent) |
| 33 |
{ |
| 34 |
QVBoxLayout *vlayout = new QVBoxLayout(this); |
| 35 |
|
| 36 |
QHBoxLayout *hlayout = new QHBoxLayout(); |
| 37 |
QHBoxLayout *hlayout1 = new QHBoxLayout(); |
| 38 |
|
| 39 |
KColorButton *btn1 = new KColorButton(); |
| 40 |
KColorButton *btn2 = new KColorButton(); |
| 41 |
btn2->setBackgroundColor(Qt::cyan); |
| 42 |
KColorButton *btn3 = new KColorButton(); |
| 43 |
btn3->setBackgroundColor(Qt::darkYellow); |
| 44 |
KColorButton *btn4 = new KColorButton(); |
| 45 |
btn4->setBackgroundColor(Qt::red); |
| 46 |
KColorButton *btn5 = new KColorButton(); |
| 47 |
btn5->setBackgroundColor(Qt::gray); |
| 48 |
btn5->setButtonType(KColorButton::CheckedRect); |
| 49 |
KColorButton *btn6 = new KColorButton(); |
| 50 |
btn6->setBackgroundColor(Qt::green); |
| 51 |
btn6->setButtonType(KColorButton::CheckedRect); |
| 52 |
KColorButton *btn7 = new KColorButton(); |
| 53 |
btn7->setBackgroundColor(Qt::darkCyan); |
| 54 |
btn7->setButtonType(KColorButton::CheckedRect); |
| 55 |
KColorButton *btn8 = new KColorButton(); |
| 56 |
btn8->setBackgroundColor(Qt::darkRed); |
| 57 |
btn8->setButtonType(KColorButton::CheckedRect); |
| 58 |
|
| 59 |
QButtonGroup *group = new QButtonGroup(this); |
| 60 |
group->addButton(btn1); |
| 61 |
group->addButton(btn2); |
| 62 |
group->addButton(btn3); |
| 63 |
group->addButton(btn4); |
| 64 |
group->addButton(btn5); |
| 65 |
group->addButton(btn6); |
| 66 |
group->addButton(btn7); |
| 67 |
group->addButton(btn8); |
| 68 |
group->setExclusive(false); // 方形按钮是否可以多选 false为可以多选 |
| 69 |
|
| 70 |
// 方形第一行 |
| 71 |
hlayout->addStretch(); |
| 72 |
hlayout->setSpacing(10); |
| 73 |
hlayout->addWidget(btn1); |
| 74 |
hlayout->addWidget(btn2); |
| 75 |
hlayout->addWidget(btn3); |
| 76 |
hlayout->addWidget(btn4); |
| 77 |
hlayout->addStretch(); |
| 78 |
|
| 79 |
// 方形第二行 |
| 80 |
hlayout1->addStretch(); |
| 81 |
hlayout1->setSpacing(10); |
| 82 |
hlayout1->addWidget(btn5); |
| 83 |
hlayout1->addWidget(btn6); |
| 84 |
hlayout1->addWidget(btn7); |
| 85 |
hlayout1->addWidget(btn8); |
| 86 |
hlayout1->addStretch(); |
| 87 |
|
| 88 |
// 圆形 |
| 89 |
KColorButton *btn9 = new KColorButton(); |
| 90 |
btn9->setBackgroundColor(Qt::gray); |
| 91 |
btn9->setButtonType(KColorButton::Circle); |
| 92 |
KColorButton *btn10 = new KColorButton(); |
| 93 |
btn10->setBackgroundColor(Qt::green); |
| 94 |
btn10->setButtonType(KColorButton::Circle); |
| 95 |
KColorButton *btn11 = new KColorButton(); |
| 96 |
btn11->setBackgroundColor(Qt::darkCyan); |
| 97 |
btn11->setButtonType(KColorButton::Circle); |
| 98 |
KColorButton *btn12 = new KColorButton(); |
| 99 |
btn12->setBackgroundColor(Qt::darkRed); |
| 100 |
btn12->setButtonType(KColorButton::Circle); |
| 101 |
|
| 102 |
QButtonGroup *group1 = new QButtonGroup(this); |
| 103 |
group1->addButton(btn9); |
| 104 |
group1->addButton(btn10); |
| 105 |
group1->addButton(btn11); |
| 106 |
group1->addButton(btn12); |
| 107 |
group1->setExclusive(false); // 圆形形按钮是否可以多选 false为可以多选 |
| 108 |
|
| 109 |
QHBoxLayout *hlayout2 = new QHBoxLayout(); |
| 110 |
hlayout2->addStretch(); |
| 111 |
hlayout2->addWidget(btn9); |
| 112 |
hlayout2->addWidget(btn10); |
| 113 |
hlayout2->addWidget(btn11); |
| 114 |
hlayout2->addWidget(btn12); |
| 115 |
hlayout2->addStretch(); |
| 116 |
|
| 117 |
vlayout->addLayout(hlayout); |
| 118 |
vlayout->addLayout(hlayout1); |
| 119 |
vlayout->addLayout(hlayout2); |
| 120 |
// vlayout->setSizeConstraint(QLayout::SizeConstraint::SetFixedSize); |
| 121 |
this->setFixedSize(300, 240); |
| 122 |
} |
| 123 |
|
| 124 |
Widget::~Widget() |
| 125 |
{ |
| 126 |
} |