Create widget at mouse click

前端 未结 1 1104
囚心锁ツ
囚心锁ツ 2021-01-27 10:48

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 *         


        
1条回答
  •  [愿得一人]
    2021-01-27 11:28

    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());
    }
    

    0 讨论(0)
提交回复
热议问题