[PyQt] no mouseMoveEvent in QTextBrowser?

martin.hammer at de.thalesgroup.com martin.hammer at de.thalesgroup.com
Mon Jan 21 13:50:38 GMT 2008


>On Monday 21 January 2008, [EMAIL PROTECTED] wrote:
>> ...
>>
>> >You probably want QWidget.setMouseTracking().
>> >
>> >Phil
>>
>> Hm, mouseTracking is set in the textBrowser, the centralWidget and the
>> QMainWindow. Um, shall I say, I'm running under Windows XP?
>
>You need to post a short, complete example that demonstrates the problem.
>
>Phil

#Here is the designer ui (ui_untitled.py):
#----------------------------------------
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'untitled.ui'
#
# Created: Mon Jan 21 14:38:34 2008
#      by: PyQt4 UI code generator 4.3.3
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
 
MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,293,250).size()).expandedTo(MainWindow.minimumSizeHint()))
        MainWindow.setMouseTracking(True)

        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setMouseTracking(True)
        self.centralwidget.setObjectName("centralwidget")

        self.textBrowser = QtGui.QTextBrowser(self.centralwidget)
        self.textBrowser.setGeometry(QtCore.QRect(10,10,256,192))
        self.textBrowser.setMouseTracking(True)
        self.textBrowser.setObjectName("textBrowser")
        MainWindow.setCentralWidget(self.centralwidget)

        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
 MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", 
"MainWindow", None, QtGui.QApplication.UnicodeUTF8))

# and here the main app
#----------------------
#!/usr/bin/env python

import sys
from PyQt4 import QtCore, QtGui
from ui_untitled import Ui_MainWindow

eventTypes = {
  0: "None",
  1: "Timer",
  2: "MouseButtonPress",
  3: "MouseButtonRelease",
  4: "MouseButtonDblClick",
  5: "MouseMove",
  6: "KeyPress",
  7: "KeyRelease",
  8: "FocusIn",
  9: "FocusOut",
  10: "Enter",
  11: "Leave",
  12: "Paint",
  13: "Move",
  14: "Resize",
  17: "Show",
  18: "Hide",
  19: "Close",
  21: "ParentChange",
  24: "WindowActivate",
  25: "WindowDeactivate",
  26: "ShowToParent",
  27: "HideToParent",
  31: "Wheel",
# some deleted ...
  178: "ContentsRectChange"
}



class MainWindowForm(QtGui.QMainWindow):
  def __init__(self, parent=None):
    QtGui.QMainWindow.__init__(self)

    self.ui = Ui_MainWindow()
    self.ui.setupUi(self)
    self.ui.textBrowser.installEventFilter(self)
  # end def __init__

  def eventFilter(self, obj, ev):
    if eventTypes.has_key(ev.type()):
      et = eventTypes[ev.type()]
    else:
      et = "unknown"
    # end if
    print "%s: %s" % (obj, et)
    return True
  # end def eventFilter

  def mouseMoveEvent(self, ev):
    print "centralwidget mouse move"

# end class MainWindowForm

if __name__ == "__main__":
  app = QtGui.QApplication(sys.argv)
  win = MainWindowForm()
  win.show()
  sys.exit(app.exec_())
# end if


Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20080121/1275045a/attachment.html


More information about the PyQt mailing list