Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to make a function, which will create new labels on mouse press?
Forum Updated to NodeBB v4.3 + New Features

How to make a function, which will create new labels on mouse press?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 221 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ddryomyssD Offline
    ddryomyssD Offline
    ddryomyss
    wrote on last edited by
    #1

    So here is what I came up with:

    void MainWindow::mousePressEvent(QMouseEvent *mpe)
    {
        QLabel *label = new QLabel(this);
        label->setText(QString("%1, %2").arg(mpe->x()).arg(mpe->y()));
        label->setGeometry(mpe->x(),mpe->y(),100,100);
    }
    

    But of course it doesn't work and I have no idea why.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You do not call show on your label object.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      ddryomyssD 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        You do not call show on your label object.

        ddryomyssD Offline
        ddryomyssD Offline
        ddryomyss
        wrote on last edited by
        #3

        @SGaist oh, really... how dumb it is
        Thank you!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved