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. Click with the mouse through a label
Forum Updated to NodeBB v4.3 + New Features

Click with the mouse through a label

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 474 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.
  • D Offline
    D Offline
    danga96
    wrote on last edited by
    #1

    hello to the whole community Qt Forum,
    I would like to know if there is an option for qLabel that allows me to make it transparent only for the mouse, but in reality it must be seen; That is, this label contains a text, but I need to click below.
    I hope I was clear
    Thanks in advance :)

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Yes, you just need to reimplement the mouse click event and set accepted property to false.

      Example for widgets:

      void MyLabel::mousePressEvent(QMouseEvent *event) {
        QLabel::mousePressEvent(event);
        event.setAccepted(false);
      }
      
      void MyLabel::mouseReleaseEvent(QMouseEvent *event) {
        QLabel::mouseReleaseEvent(event);
        event.setAccepted(false);
      }
      

      QML example:

      Label {
        MouseArea {
          onClicked: mouse.accepted = false
        }
      }
      

      Brain-to-terminal, untested. But might work :-)

      (Z(:^

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

        Hi,

        IIRC, you can set the Qt::WA_TransparentForMouseEvents widget attribute and it should behave the way you'd like.

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

        1 Reply Last reply
        2

        • Login

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