[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] no mouseMoveEvent in QTextBrowser?
From: martin.hammer () de ! thalesgroup ! com
Date: 2008-01-21 13:50:38
Message-ID: OF4CC3C9E4.BCD25A3B-ONC12573D7.004B82DF-C12573D7.004BEA95 () thales-tek ! de
[Download RAW message or body]
Dies ist eine mehrteilige Nachricht im MIME-Format.
Dies ist eine mehrteilige Nachricht im MIME-Format.
--=_alternative 004BEA93C12573D7_=
Content-Type: text/plain; charset="US-ASCII"
> 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
--=_alternative 004BEA93C12573D7_=
Content-Type: text/html; charset="US-ASCII"
<br><tt><font size=3>>On Monday 21 January 2008, [EMAIL PROTECTED] wrote:<br>
>> ...<br>
>><br>
>> >You probably want QWidget.setMouseTracking().<br>
>> ><br>
>> >Phil<br>
>><br>
>> Hm, mouseTracking is set in the textBrowser, the centralWidget
and the<br>
>> QMainWindow. Um, shall I say, I'm running under Windows XP?<br>
><br>
>You need to post a short, complete example that demonstrates the problem.<br>
><br>
>Phil<br>
</font></tt>
<br><tt><font size=3>#Here is the designer ui (ui_untitled.py):</font></tt>
<br><tt><font size=3>#----------------------------------------</font></tt>
<br><tt><font size=3># -*- coding: utf-8 -*-</font></tt>
<br>
<br><tt><font size=3># Form implementation generated from reading ui file
'untitled.ui'</font></tt>
<br><tt><font size=3>#</font></tt>
<br><tt><font size=3># Created: Mon Jan 21 14:38:34 2008</font></tt>
<br><tt><font size=3># by: PyQt4 UI code generator
4.3.3</font></tt>
<br><tt><font size=3>#</font></tt>
<br><tt><font size=3># WARNING! All changes made in this file will be \
lost!</font></tt> <br>
<br><tt><font size=3>from PyQt4 import QtCore, QtGui</font></tt>
<br>
<br><tt><font size=3>class Ui_MainWindow(object):</font></tt>
<br><tt><font size=3> def setupUi(self, MainWindow):</font></tt>
<br><tt><font size=3> \
MainWindow.setObjectName("MainWindow")</font></tt> <br><tt><font \
size=3> \
MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,293,250).size()).expandedTo(MainWindow.minimumSizeHint()))</font></tt>
<br><tt><font size=3> \
MainWindow.setMouseTracking(True)</font></tt> <br>
<br><tt><font size=3> self.centralwidget = \
QtGui.QWidget(MainWindow)</font></tt> <br><tt><font size=3> \
self.centralwidget.setMouseTracking(True)</font></tt> <br><tt><font \
size=3> \
self.centralwidget.setObjectName("centralwidget")</font></tt> <br>
<br><tt><font size=3> self.textBrowser = \
QtGui.QTextBrowser(self.centralwidget)</font></tt> <br><tt><font size=3> \
self.textBrowser.setGeometry(QtCore.QRect(10,10,256,192))</font></tt> \
<br><tt><font size=3> \
self.textBrowser.setMouseTracking(True)</font></tt> <br><tt><font size=3> \
\
self.textBrowser.setObjectName("textBrowser")</font></tt> <br><tt><font \
size=3> \
MainWindow.setCentralWidget(self.centralwidget)</font></tt> <br>
<br><tt><font size=3> self.statusbar = \
QtGui.QStatusBar(MainWindow)</font></tt> <br><tt><font size=3> \
self.statusbar.setObjectName("statusbar")</font></tt> <br><tt><font \
size=3> \
MainWindow.setStatusBar(self.statusbar)</font></tt> <br>
<br><tt><font size=3> \
self.retranslateUi(MainWindow)</font></tt> <br><tt><font size=3> \
QtCore.QMetaObject.connectSlotsByName(MainWindow)</font></tt> <br>
<br><tt><font size=3> def retranslateUi(self, MainWindow):</font></tt>
<br><tt><font size=3> \
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", \
"MainWindow", None, QtGui.QApplication.UnicodeUTF8))</font></tt> <br>
<br><tt><font size=3># and here the main app</font></tt>
<br><tt><font size=3>#----------------------</font></tt>
<br><tt><font size=3>#!/usr/bin/env python</font></tt>
<br>
<br><tt><font size=3>import sys</font></tt>
<br><tt><font size=3>from PyQt4 import QtCore, QtGui</font></tt>
<br><tt><font size=3>from ui_untitled import Ui_MainWindow</font></tt>
<br>
<br><tt><font size=3>eventTypes = {</font></tt>
<br><tt><font size=3> 0: "None",</font></tt>
<br><tt><font size=3> 1: "Timer",</font></tt>
<br><tt><font size=3> 2: "MouseButtonPress",</font></tt>
<br><tt><font size=3> 3: "MouseButtonRelease",</font></tt>
<br><tt><font size=3> 4: "MouseButtonDblClick",</font></tt>
<br><tt><font size=3> 5: "MouseMove",</font></tt>
<br><tt><font size=3> 6: "KeyPress",</font></tt>
<br><tt><font size=3> 7: "KeyRelease",</font></tt>
<br><tt><font size=3> 8: "FocusIn",</font></tt>
<br><tt><font size=3> 9: "FocusOut",</font></tt>
<br><tt><font size=3> 10: "Enter",</font></tt>
<br><tt><font size=3> 11: "Leave",</font></tt>
<br><tt><font size=3> 12: "Paint",</font></tt>
<br><tt><font size=3> 13: "Move",</font></tt>
<br><tt><font size=3> 14: "Resize",</font></tt>
<br><tt><font size=3> 17: "Show",</font></tt>
<br><tt><font size=3> 18: "Hide",</font></tt>
<br><tt><font size=3> 19: "Close",</font></tt>
<br><tt><font size=3> 21: "ParentChange",</font></tt>
<br><tt><font size=3> 24: "WindowActivate",</font></tt>
<br><tt><font size=3> 25: "WindowDeactivate",</font></tt>
<br><tt><font size=3> 26: "ShowToParent",</font></tt>
<br><tt><font size=3> 27: "HideToParent",</font></tt>
<br><tt><font size=3> 31: "Wheel",</font></tt>
<br><tt><font size=3># some deleted ...</font></tt>
<br><tt><font size=3> 178: "ContentsRectChange"</font></tt>
<br><tt><font size=3>}</font></tt>
<br>
<br>
<br>
<br><tt><font size=3>class MainWindowForm(QtGui.QMainWindow):</font></tt>
<br><tt><font size=3> def __init__(self, parent=None):</font></tt>
<br><tt><font size=3> QtGui.QMainWindow.__init__(self)</font></tt>
<br>
<br><tt><font size=3> self.ui = Ui_MainWindow()</font></tt>
<br><tt><font size=3> self.ui.setupUi(self)</font></tt>
<br><tt><font size=3> \
self.ui.textBrowser.installEventFilter(self)</font></tt> <br><tt><font size=3> \
# end def __init__</font></tt> <br>
<br><tt><font size=3> def eventFilter(self, obj, ev):</font></tt>
<br><tt><font size=3> if eventTypes.has_key(ev.type()):</font></tt>
<br><tt><font size=3> et = eventTypes[ev.type()]</font></tt>
<br><tt><font size=3> else:</font></tt>
<br><tt><font size=3> et = "unknown"</font></tt>
<br><tt><font size=3> # end if</font></tt>
<br><tt><font size=3> print "%s: %s" % (obj, et)</font></tt>
<br><tt><font size=3> return True</font></tt>
<br><tt><font size=3> # end def eventFilter</font></tt>
<br>
<br><tt><font size=3> def mouseMoveEvent(self, ev):</font></tt>
<br><tt><font size=3> print "centralwidget mouse \
move"</font></tt> <br>
<br><tt><font size=3># end class MainWindowForm</font></tt>
<br>
<br><tt><font size=3>if __name__ == "__main__":</font></tt>
<br><tt><font size=3> app = QtGui.QApplication(sys.argv)</font></tt>
<br><tt><font size=3> win = MainWindowForm()</font></tt>
<br><tt><font size=3> win.show()</font></tt>
<br><tt><font size=3> sys.exit(app.exec_())</font></tt>
<br><tt><font size=3># end if</font></tt>
<br>
<br>
<br><tt><font size=3>Martin</font></tt>
<br>
--=_alternative 004BEA93C12573D7_=--
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic