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. QTouchEvent confusion

QTouchEvent confusion

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.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.
  • M Offline
    M Offline
    mbrophy
    wrote on last edited by
    #1

    I haven't been able to find a tutorial on handling touch events in PyQt or PySide or figure it out from the documentation. Does anyone have a simple program to illustrate how it works?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      did you read the "docs":http://qt-project.org/doc/qt-5.0/qtgui/qtouchevent.html#event-handling?!

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbrophy
        wrote on last edited by
        #3

        Yes, that's why I'm confused. In the code below, I can display mouse events but not touch events. What am I doing wrong?

        @import sys
        from PySide import QtGui, QtCore

        class Window(QtGui.QMainWindow):
        def init(self):
        QtGui.QMainWindow.init(self)
        self.setAttribute(QtCore.Qt.WA_AcceptTouchEvents)
        widget = QtGui.QWidget(self)
        layout = QtGui.QVBoxLayout(widget)
        self.edit = QtGui.QLineEdit(self)
        self.list = QtGui.QListWidget(self)
        layout.addWidget(self.edit)
        layout.addWidget(self.list)
        self.setCentralWidget(widget)

        def eventFilter(self, source, event):
            if event.type() == QtCore.QEvent.MouseMove:
                if event.buttons() == QtCore.Qt.NoButton:
                    pos = event.pos()
                    self.edit.setText('x: %d, y: %d' % (pos.x(), pos.y()))
                else:
                    pass # do other stuff
            elif event.type() == QtCore.QEvent.TouchBegin:
                pos = event.pos()
                self.edit.setText('touch x: %d, y: %d' % (pos.x(), pos.y()))
        
            return QtGui.QMainWindow.eventFilter(self, source, event)
        

        if name == 'main':
        app = QtGui.QApplication(sys.argv)
        win = Window()
        win.show()
        app.installEventFilter(win)
        sys.exit(app.exec_())
        @

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          read the link i've posted again!! this time really ... it's all mentioned very well there...

          Instead using pos() of QTouchEvent (which btw. doesn't even exist for this type of event) you should use touchPoints().

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mbrophy
            wrote on last edited by
            #5

            Thanks for the response. I'm not receiving events from TouchBegin but I'm receiving events from MouseMove in my event filter even though I used self.setAttribute(QtCore.Qt.WA_AcceptTouchEvents) to accept touch events. There must be something I'm missing but I'm only getting started with Qt and I can't understand the docs as well as 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