I\'m new at Qt. How can I create a new widget at mouse click? I want to create a new label at every mouse click.
// works fine: MainWindow::MainWindow(QWidget *
You need to show the widget, and preferably set its position (if not using QLayout):
void MainWindow::mousePressEvent(QMouseEvent *e) { QLabel *label = new QLabel(this); label->setText("Hello"); label->show(); label->move(e->pos()); }