[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>&gt;On Monday 21 January 2008, [EMAIL PROTECTED] wrote:<br>
&gt;&gt; ...<br>
&gt;&gt;<br>
&gt;&gt; &gt;You probably want QWidget.setMouseTracking().<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;Phil<br>
&gt;&gt;<br>
&gt;&gt; Hm, mouseTracking is set in the textBrowser, the centralWidget
and the<br>
&gt;&gt; QMainWindow. Um, shall I say, I'm running under Windows XP?<br>
&gt;<br>
&gt;You need to post a short, complete example that demonstrates the problem.<br>
&gt;<br>
&gt;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># &nbsp; &nbsp; &nbsp;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>&nbsp; &nbsp; def setupUi(self, MainWindow):</font></tt>
<br><tt><font size=3>&nbsp; &nbsp; &nbsp; &nbsp; \
MainWindow.setObjectName(&quot;MainWindow&quot;)</font></tt> <br><tt><font \
size=3>&nbsp; &nbsp; &nbsp; &nbsp; \
MainWindow.resize(QtCore.QSize(QtCore.QRect(0,0,293,250).size()).expandedTo(MainWindow.minimumSizeHint()))</font></tt>
 <br><tt><font size=3>&nbsp; &nbsp; &nbsp; &nbsp; \
MainWindow.setMouseTracking(True)</font></tt> <br>
<br><tt><font size=3>&nbsp; &nbsp; &nbsp; &nbsp; self.centralwidget = \
QtGui.QWidget(MainWindow)</font></tt> <br><tt><font size=3>&nbsp; &nbsp; &nbsp; \
&nbsp; self.centralwidget.setMouseTracking(True)</font></tt> <br><tt><font \
size=3>&nbsp; &nbsp; &nbsp; &nbsp; \
self.centralwidget.setObjectName(&quot;centralwidget&quot;)</font></tt> <br>
<br><tt><font size=3>&nbsp; &nbsp; &nbsp; &nbsp; self.textBrowser = \
QtGui.QTextBrowser(self.centralwidget)</font></tt> <br><tt><font size=3>&nbsp; &nbsp; \
&nbsp; &nbsp; self.textBrowser.setGeometry(QtCore.QRect(10,10,256,192))</font></tt> \
<br><tt><font size=3>&nbsp; &nbsp; &nbsp; &nbsp; \
self.textBrowser.setMouseTracking(True)</font></tt> <br><tt><font size=3>&nbsp; \
&nbsp; &nbsp; &nbsp; \
self.textBrowser.setObjectName(&quot;textBrowser&quot;)</font></tt> <br><tt><font \
size=3>&nbsp; &nbsp; &nbsp; &nbsp; \
MainWindow.setCentralWidget(self.centralwidget)</font></tt> <br>
<br><tt><font size=3>&nbsp; &nbsp; &nbsp; &nbsp; self.statusbar = \
QtGui.QStatusBar(MainWindow)</font></tt> <br><tt><font size=3>&nbsp; &nbsp; &nbsp; \
&nbsp; self.statusbar.setObjectName(&quot;statusbar&quot;)</font></tt> <br><tt><font \
size=3>&nbsp; &nbsp; &nbsp; &nbsp; \
MainWindow.setStatusBar(self.statusbar)</font></tt> <br>
<br><tt><font size=3>&nbsp; &nbsp; &nbsp; &nbsp; \
self.retranslateUi(MainWindow)</font></tt> <br><tt><font size=3>&nbsp; &nbsp; &nbsp; \
&nbsp; QtCore.QMetaObject.connectSlotsByName(MainWindow)</font></tt> <br>
<br><tt><font size=3>&nbsp; &nbsp; def retranslateUi(self, MainWindow):</font></tt>
<br><tt><font size=3>&nbsp; &nbsp; &nbsp; &nbsp; \
MainWindow.setWindowTitle(QtGui.QApplication.translate(&quot;MainWindow&quot;, \
&quot;MainWindow&quot;, 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>&nbsp; 0: &quot;None&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 1: &quot;Timer&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 2: &quot;MouseButtonPress&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 3: &quot;MouseButtonRelease&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 4: &quot;MouseButtonDblClick&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 5: &quot;MouseMove&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 6: &quot;KeyPress&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 7: &quot;KeyRelease&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 8: &quot;FocusIn&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 9: &quot;FocusOut&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 10: &quot;Enter&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 11: &quot;Leave&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 12: &quot;Paint&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 13: &quot;Move&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 14: &quot;Resize&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 17: &quot;Show&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 18: &quot;Hide&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 19: &quot;Close&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 21: &quot;ParentChange&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 24: &quot;WindowActivate&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 25: &quot;WindowDeactivate&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 26: &quot;ShowToParent&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 27: &quot;HideToParent&quot;,</font></tt>
<br><tt><font size=3>&nbsp; 31: &quot;Wheel&quot;,</font></tt>
<br><tt><font size=3># some deleted ...</font></tt>
<br><tt><font size=3>&nbsp; 178: &quot;ContentsRectChange&quot;</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>&nbsp; def __init__(self, parent=None):</font></tt>
<br><tt><font size=3>&nbsp; &nbsp; QtGui.QMainWindow.__init__(self)</font></tt>
<br>
<br><tt><font size=3>&nbsp; &nbsp; self.ui = Ui_MainWindow()</font></tt>
<br><tt><font size=3>&nbsp; &nbsp; self.ui.setupUi(self)</font></tt>
<br><tt><font size=3>&nbsp; &nbsp; \
self.ui.textBrowser.installEventFilter(self)</font></tt> <br><tt><font size=3>&nbsp; \
# end def __init__</font></tt> <br>
<br><tt><font size=3>&nbsp; def eventFilter(self, obj, ev):</font></tt>
<br><tt><font size=3>&nbsp; &nbsp; if eventTypes.has_key(ev.type()):</font></tt>
<br><tt><font size=3>&nbsp; &nbsp; &nbsp; et = eventTypes[ev.type()]</font></tt>
<br><tt><font size=3>&nbsp; &nbsp; else:</font></tt>
<br><tt><font size=3>&nbsp; &nbsp; &nbsp; et = &quot;unknown&quot;</font></tt>
<br><tt><font size=3>&nbsp; &nbsp; # end if</font></tt>
<br><tt><font size=3>&nbsp; &nbsp; print &quot;%s: %s&quot; % (obj, et)</font></tt>
<br><tt><font size=3>&nbsp; &nbsp; return True</font></tt>
<br><tt><font size=3>&nbsp; # end def eventFilter</font></tt>
<br>
<br><tt><font size=3>&nbsp; def mouseMoveEvent(self, ev):</font></tt>
<br><tt><font size=3>&nbsp; &nbsp; print &quot;centralwidget mouse \
move&quot;</font></tt> <br>
<br><tt><font size=3># end class MainWindowForm</font></tt>
<br>
<br><tt><font size=3>if __name__ == &quot;__main__&quot;:</font></tt>
<br><tt><font size=3>&nbsp; app = QtGui.QApplication(sys.argv)</font></tt>
<br><tt><font size=3>&nbsp; win = MainWindowForm()</font></tt>
<br><tt><font size=3>&nbsp; win.show()</font></tt>
<br><tt><font size=3>&nbsp; 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