The dialog contains Text Label
and buttons Reset
OK
Cancel
During initialization displays text "Simple dialog correctly initialized"
The button Reset clear text
The button OK displays text "OK Button clicked ..."
The button Cancel close dialog
1. Via Qt designer create new form File->New Form...
and select
Dialog with Buttons Bottom
2. We create Text Label so move Label icon to form
3. In Property editor rename label name to m_pLabel
4. In the same way create button Reset
5. Rename button name to m_pResetButton and button text to Reset
In the same way rename button OK objectName = m_pOkButton
button Close objectName = m_pCancelButton
and dialog objectName = CSimpleDialog
6. Set signal and slot for buttons Reset a Cancel.
We will need achieve clear Text Label after to press button Reset and close dialog after to press button Close. Therefore change designer to signal/slot mod.
7. Now press left mouse button Reset and move mouse cursor to Text Label. It`s automatically shows Configure connection dialog. We set signal clicked() and slot clear()
8. Delete signal and slot for button OK in Signal/Slot Editor by press button minus.
We will write signal and slot for this button later in CSimpleDialog class.
9. In Signal/Slot Editor change Close button slot reject() to slot close()
10. Now dialog looks like this:
These arrows represent signal influence to slot. These arrows can be manipulated visually, and provide the user with an overview of the form's connection logic.
This class is inherit from Ui simple dialog Ui::CSimpleDialog. The important thing is makro Q_OBJECT ,
which allow acces to simple dialog Ui data.
This class contains function void OkButtonClicked();
which is declaret as slot private slots:
This funkce write to Text Label "OK Button clicked ..."
string
13. In class constructor
CSimpleDialog::CSimpleDialog(QWidget *parent): QDialog(parent){ setupUi(this);// Set label text m_pLabel->setText("Simple dialog correctly initialized");// Set signal and slot for "OK Button"connect(m_pOkButton, SIGNAL(clicked()), this, SLOT(OkButtonClicked()));}
set as Ui this class setupUi(this);
set to Text Labelu initialization text m_pLabel->setText("Simple dialog correctly initialized");
and creage signal and slot for button OK connect(m_pOkButton, SIGNAL(clicked()), this, SLOT(OkButtonClicked()));