0

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 ?

McLan
  • 2,552
  • 9
  • 51
  • 85
  • 3
    You may have the button already created, invisible and set it visible when some event occurs... – Sam Apr 11 '13 at 20:21
  • 1
    Have a look at the `ui_*.h`-files generated by Qt. You'll see how that magic Qt-GUI stuff is translated to code. – Misch Apr 11 '13 at 20:22
  • 1
    Create an object of QPushButton class in the handler for the "exit" button. And assign a new slot for that new button using connect(). – Vaibhav Desai Apr 11 '13 at 20:22

1 Answers1

3

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
}
masoud
  • 55,379
  • 16
  • 141
  • 208