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. Capturing mouseEvents
Qt 6.11 is out! See what's new in the release blog

Capturing mouseEvents

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.3k Views 1 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.
  • G Offline
    G Offline
    gabello306
    wrote on last edited by
    #1

    I have a QTabWiget with three pages. On one page I have a QListWidget. I have implemented this to capture mouse events.

    void NotebookView::mousePressEvent(QMouseEvent* event)
    {
        if(event->button == Qt::LeftButton)
        {
            printf("Left Mouse Button\n");
        }
    }
    

    The NotebookView is the QTabWidget. When I press the mouse outside the QListWidget, inside the QTabWidget, then I get a mouse event. What I really need is to get the event when I click inside the QListWidget. How do I get the event inside the QListWidget?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gabello306
      wrote on last edited by
      #2

      I have created a separate class of QListWidget instead of using qtcreator and now I can use the mouse events. Only how do I connect the QListWidget to the individual tab page?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gabello306
        wrote on last edited by
        #3

        Figured out the problem. this->widget(<page>) will assign the QListWidget to the QTabWidget.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gabello306
          wrote on last edited by
          #4

          I have done everything I can think of but I still can't select of the items in the list. Any ideas?

          Pl45m4P jsulmJ 2 Replies Last reply
          0
          • G gabello306

            I have done everything I can think of but I still can't select of the items in the list. Any ideas?

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #5

            @gabello306

            Just use the provided signal for your List widget item clicks.
            Connect a function to itemClicked and you're good.

            • https://doc.qt.io/qt-6/qlistwidget.html#itemClicked

            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            2
            • G gabello306

              I have done everything I can think of but I still can't select of the items in the list. Any ideas?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @gabello306 said in Capturing mouseEvents:

              Any ideas?

              Maybe because you've overridden the mousePressEvent?
              Do you call inherited mousePressEvent in your mousePressEvent?

              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