-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
64 lines (49 loc) · 1.83 KB
/
mainwindow.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QWidget{parent}
{
setWindowTitle("QLineEdit - Input Masks and Validators");
setMinimumSize(400, 600);
inputMaskWidget = new InputMaskDemo();
validatorWidget = new ValidatorDemo();
radioInputMask = new QRadioButton("Input Mask");
radioValidator = new QRadioButton("Validator");
QGroupBox *selectorGroup = new QGroupBox("Select Widget");
selectorGroup->setStyleSheet("background:#80c342");
QHBoxLayout *selectorLayout = new QHBoxLayout(selectorGroup);
selectorLayout->addWidget(radioInputMask);
selectorLayout->addWidget(radioValidator);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(selectorGroup);
layout->addWidget(inputMaskWidget);
layout->addWidget(validatorWidget);
// Used to expand horizontally - added apart from the instructions
inputMaskWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
validatorWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// Uncomment the below to ensure the space below is always static and filled - ensure to comment out above sizePolicies for both widgets then
// layout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
connect(radioInputMask, &QRadioButton::toggled,
this, &MainWindow::onInputMaskSel);
connect(radioValidator, &QRadioButton::toggled,
this, &MainWindow::onValidatorSel);
radioInputMask->setChecked(true);
}
MainWindow::~MainWindow()
{
}
void MainWindow::onInputMaskSel(bool checked)
{
if(checked)
{
validatorWidget->hide();
inputMaskWidget->show();
}
}
void MainWindow::onValidatorSel(bool checked)
{
if(checked)
{
inputMaskWidget->hide();
validatorWidget->show();
}
}