-
Notifications
You must be signed in to change notification settings - Fork 14
/
home_page.cpp
43 lines (34 loc) · 1.13 KB
/
home_page.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "home_page.h"
HomePage::HomePage(QWidget *parent)
: QWidget(parent)
{
layout = new QVBoxLayout(this);
topLayout = new QHBoxLayout();
switchLayout = new QStackedLayout();
queryEditor = new QLineEdit();
queryButton = new QPushButton("查词");
everydayPage = new EverydayPage();
dictPage = new DictPage();
switchLayout->addWidget(everydayPage);
switchLayout->addWidget(dictPage);
topLayout->addSpacing(20);
topLayout->addWidget(queryEditor);
topLayout->addWidget(queryButton);
topLayout->addSpacing(20);
layout->addSpacing(5);
layout->addLayout(topLayout);
layout->addLayout(switchLayout);
connect(queryEditor, &QLineEdit::textChanged, this, &HomePage::queryWord);
connect(queryEditor, &QLineEdit::returnPressed, this, &HomePage::queryWord);
connect(queryButton, &QPushButton::clicked, this, &HomePage::queryWord);
}
void HomePage::queryWord()
{
queryEditor->setFocus();
if (queryEditor->text().isEmpty()) {
switchLayout->setCurrentIndex(0);
return;
}
dictPage->start(queryEditor->text());
switchLayout->setCurrentIndex(1);
}