Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/commandwidget.cpp
Show All 31 Lines | 25 | { | |||
---|---|---|---|---|---|
32 | //Making child layouts in the order you want to put them | 32 | //Making child layouts in the order you want to put them | ||
33 | // onto the mainLayout | 33 | // onto the mainLayout | ||
34 | lineCommand = new QLineEdit(this); | 34 | lineCommand = new QLineEdit(this); | ||
35 | lineCommand->setPlaceholderText(tr("Send Command")); | 35 | lineCommand->setPlaceholderText(tr("Send Command")); | ||
36 | 36 | | |||
37 | //we have a few buttons to make here. Lets name this newButton so its easier to reuse | 37 | //we have a few buttons to make here. Lets name this newButton so its easier to reuse | ||
38 | auto newButton = new QPushButton(tr("Send"), this); | 38 | auto newButton = new QPushButton(tr("Send"), this); | ||
39 | connect(newButton, &QPushButton::clicked, this, [this] { | 39 | connect(newButton, &QPushButton::clicked, this, [this] { | ||
40 | if (!lineCommand->text().isEmpty()) | ||||
41 | { | ||||
40 | emit commandPressed(lineCommand->text()); | 42 | emit commandPressed(lineCommand->text()); | ||
41 | lineCommand->clear(); | 43 | lineCommand->clear(); | ||
44 | } | ||||
42 | }); | 45 | }); | ||
43 | //When you have created a Row put the items into layout. | 46 | //When you have created a Row put the items into layout. | ||
44 | auto hBoxLayout = new QHBoxLayout; | 47 | auto hBoxLayout = new QHBoxLayout; | ||
45 | hBoxLayout->addWidget(lineCommand); | 48 | hBoxLayout->addWidget(lineCommand); | ||
46 | hBoxLayout->addWidget(newButton); | 49 | hBoxLayout->addWidget(newButton); | ||
47 | //Put the Layout or Widget on the mainLayout when its finished. | 50 | //Put the Layout or Widget on the mainLayout when its finished. | ||
48 | //This will free your pointers for reuse. | 51 | //This will free your pointers for reuse. | ||
49 | mainLayout->addLayout(hBoxLayout); | 52 | mainLayout->addLayout(hBoxLayout); | ||
50 | 53 | | |||
51 | //Start making items for the next layout to place onto the mainLayout. | 54 | //Start making items for the next layout to place onto the mainLayout. | ||
52 | lineMessage = new QLineEdit(this); | 55 | lineMessage = new QLineEdit(this); | ||
53 | lineMessage->setPlaceholderText(tr("Show Message")); | 56 | lineMessage->setPlaceholderText(tr("Show Message")); | ||
54 | 57 | | |||
55 | //Reuse our button pointer. | 58 | //Reuse our button pointer. | ||
56 | newButton = new QPushButton(tr("Send"), this); | 59 | newButton = new QPushButton(tr("Send"), this); | ||
57 | 60 | | |||
58 | connect(newButton, &QPushButton::clicked, this, [this] { | 61 | connect(newButton, &QPushButton::clicked, this, [this] { | ||
62 | if (!lineMessage->text().isEmpty()) | ||||
63 | { | ||||
59 | emit messagePressed(lineMessage->text()); | 64 | emit messagePressed(lineMessage->text()); | ||
60 | lineMessage->clear(); | 65 | lineMessage->clear(); | ||
66 | } | ||||
61 | }); | 67 | }); | ||
62 | 68 | | |||
63 | //We reuse the hBoxLayout pointer in the same way as the button pointer. | 69 | //We reuse the hBoxLayout pointer in the same way as the button pointer. | ||
64 | hBoxLayout = new QHBoxLayout; | 70 | hBoxLayout = new QHBoxLayout; | ||
65 | hBoxLayout->addWidget(lineMessage); | 71 | hBoxLayout->addWidget(lineMessage); | ||
66 | hBoxLayout->addWidget(newButton); | 72 | hBoxLayout->addWidget(newButton); | ||
67 | mainLayout->addLayout(hBoxLayout); | 73 | mainLayout->addLayout(hBoxLayout); | ||
68 | 74 | | |||
69 | setLayout(mainLayout); | 75 | setLayout(mainLayout); | ||
70 | } | 76 | } |