Question

I want to create a SLOT() that creates a QPushButton (or a QLineEdit) widget on my Gui (on the same frame) whenever a SIGNAL(clicked()) is emitted from a specific PushButton on my Gui. for example: when I press on "exit" a new "thanks" button appears on the same frame.

so, how do I create a new PushButton using c++ code and not the Qt-GUI tools ?

Was it helpful?

Solution

Of course, you can create widgets such as buttons without WYSIWYG tools (e.g. QtDesinger)

Write this code inside the slot of "exit" button:

void ThisWindowClass::exitClicked()
{
  // ...
  QPushButton *thanksButton = new QPushButton(this /*parent widget*/);
  connect(thanksButton, SIGNAL(clicked(bool)), this, SLOT(thanksClicked(bool)));
  // ...
}

And you must have a slot method named thanksClicked:

void ThisWindowClass::thanksClicked(bool checked)
{
 // Do something
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top