Debian Codegraph @

kysdk-qtwidgets/test/testsearchlinedit/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: Zhen Sun <[email protected]>
20 *
21 */
22
23 #include "widget.h"
24
25 #include <QBoxLayout>
26 #include <QLabel>
27
28 Widget::Widget(QWidget *parent)
29 : KWidget(parent)
30 {
31 QVBoxLayout *mainLayout = new QVBoxLayout;
32 mainLayout->addStretch();
33
34 QHBoxLayout *hLayout = new QHBoxLayout;
35 m_pSearchLineEdit1 = new KSearchLineEdit(this); // 构造一个搜索框
36 // m_pSearchLineEdit1->setPlaceholderAlignment(Qt::AlignCenter); //设置placeholder的对齐方式
37 m_pSearchLineEdit1->setClearButtonEnabled(true); // 是否启用清除键(true为启用)
38 m_pSearchLineEdit1->setPlaceholderText("此处需要输入很长非常长的需要查找的内容"); // 设置placeholder的文本内容
39 m_pSearchLineEdit1->setAlignment(Qt::AlignLeft); // 设置输入内容的对齐方式
40 m_pLabel1 = new QLabel(this);
41 hLayout->addWidget(m_pSearchLineEdit1);
42
43 QPushButton *btn1 = new QPushButton(this);
44 btn1->setText("隐藏");
45 QPushButton *btn2 = new QPushButton(this);
46 btn2->setText("显示");
47 btn2->move(110, 0);
48 QPushButton *btn3 = new QPushButton(this);
49 btn3->setText("清除");
50 btn3->move(220, 0);
51
52 connect(btn1, &QPushButton::clicked, this, [=] {
53 m_pSearchLineEdit1->hide();
54 });
55 connect(btn2, &QPushButton::clicked, this, [=] {
56 m_pSearchLineEdit1->show();
57 });
58 connect(btn3, &QPushButton::clicked, this, [=] {
59 m_pSearchLineEdit1->clear();
60 });
61
62 connect(m_pSearchLineEdit1, &KSearchLineEdit::returnPressed, this, [=]() {
63 m_pLabel1->setText(QString("Search Content is:%1").arg(m_pSearchLineEdit1->text()));
64 });
65 mainLayout->addLayout(hLayout);
66 mainLayout->addWidget(m_pLabel1);
67
68 hLayout = new QHBoxLayout;
69 m_pSearchLineEdit2 = new KSearchLineEdit(this);
70 m_pLabel2 = new QLabel(this);
71 m_pSearchLineEdit2->setEnabled(false); // 设置搜索框是否可用
72 hLayout->addWidget(m_pSearchLineEdit2);
73 connect(m_pSearchLineEdit2, &KSearchLineEdit::returnPressed, this, [=]() {
74 m_pLabel2->setText(QString("Search Content is:%1").arg(m_pSearchLineEdit2->text()));
75 });
76 mainLayout->addLayout(hLayout);
77 mainLayout->addWidget(m_pLabel2);
78 mainLayout->addStretch();
79 baseBar()->setLayout(mainLayout);
80 }
81
82 Widget::~Widget()
83 {
84 }