Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/commandwidget.cpp
Show All 30 Lines | 25 | { | |||
---|---|---|---|---|---|
31 | //Begin making content from top to bottom or left to right. | 31 | //Begin making content from top to bottom or left to right. | ||
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; | 34 | lineCommand = new QLineEdit; | ||
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")); | 38 | auto newButton = new QPushButton(tr("Send")); | ||
39 | connect(newButton, &QPushButton::clicked, [&] { | 39 | connect(newButton, &QPushButton::clicked, this, [this] { | ||
40 | emit(commandPressed(lineCommand->text())); | 40 | emit(commandPressed(lineCommand->text())); | ||
41 | lineCommand->clear(); | 41 | lineCommand->clear(); | ||
42 | }); | 42 | }); | ||
43 | //When you have created a Row put the items into layout. | 43 | //When you have created a Row put the items into layout. | ||
44 | auto hBoxLayout = new QHBoxLayout; | 44 | auto hBoxLayout = new QHBoxLayout; | ||
45 | hBoxLayout->addWidget(lineCommand); | 45 | hBoxLayout->addWidget(lineCommand); | ||
46 | hBoxLayout->addWidget(newButton); | 46 | hBoxLayout->addWidget(newButton); | ||
47 | //Put the Layout or Widget on the mainLayout when its finished. | 47 | //Put the Layout or Widget on the mainLayout when its finished. | ||
48 | //This will free your pointers for reuse. | 48 | //This will free your pointers for reuse. | ||
49 | mainLayout->addLayout(hBoxLayout); | 49 | mainLayout->addLayout(hBoxLayout); | ||
50 | 50 | | |||
51 | //Start making items for the next layout to place onto the mainLayout. | 51 | //Start making items for the next layout to place onto the mainLayout. | ||
52 | lineMessage = new QLineEdit; | 52 | lineMessage = new QLineEdit; | ||
53 | lineMessage->setPlaceholderText(tr("Show Message")); | 53 | lineMessage->setPlaceholderText(tr("Show Message")); | ||
54 | 54 | | |||
55 | //Reuse our button pointer. | 55 | //Reuse our button pointer. | ||
56 | newButton = new QPushButton(tr("Send")); | 56 | newButton = new QPushButton(tr("Send")); | ||
57 | 57 | | |||
58 | connect(newButton, &QPushButton::clicked, [&] { | 58 | connect(newButton, &QPushButton::clicked, this, [this] { | ||
59 | emit(messagePressed(lineMessage->text())); | 59 | emit(messagePressed(lineMessage->text())); | ||
60 | lineMessage->clear(); | 60 | lineMessage->clear(); | ||
61 | }); | 61 | }); | ||
62 | 62 | | |||
63 | //We reuse the hBoxLayout pointer in the same way as the button pointer. | 63 | //We reuse the hBoxLayout pointer in the same way as the button pointer. | ||
64 | hBoxLayout = new QHBoxLayout; | 64 | hBoxLayout = new QHBoxLayout; | ||
65 | hBoxLayout->addWidget(lineMessage); | 65 | hBoxLayout->addWidget(lineMessage); | ||
66 | hBoxLayout->addWidget(newButton); | 66 | hBoxLayout->addWidget(newButton); | ||
67 | mainLayout->addLayout(hBoxLayout); | 67 | mainLayout->addLayout(hBoxLayout); | ||
68 | 68 | | |||
69 | setLayout(mainLayout); | 69 | setLayout(mainLayout); | ||
70 | } | 70 | } |