[PyQt] QDockWidgetquestion
Brian Kelley
kelley at eyesopen.com
Mon Dec 22 16:22:27 GMT 2008
If you want to catch mouse events in a parent, you should install or override an eventFilter.
For example, here is an eventFilter I use on my main window to catch close events. You can catch mouse events or others in this way. “obj” is the object receiving the event and “event” is the event being received. Note that doing it this way is tricky. You may be better off making your own subclasses for all your widgets that can communicate to the mainwindow.
def eventFilter(self, obj, event):
controller = self.controller
if obj == self.mw and event.type() == QEvent.Close:
if controller and controller.db.ProcessesRunning():
opt = QtGui.QMessageBox.question(self.mw,
"Running Workflows",
"There are workflows still running, would you like to save these?\n"
"(Saved workflows will restart when the throughput is run again.)",
QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard |
QtGui.QMessageBox.Cancel)
if opt == QtGui.QMessageBox.Cancel:
event.setAccepted(False)
return True
self.controller.db.disconnect()
self.controller.db.KillRunningProcesses()
if res == QtGui.QMessageBox.Discard:
self.controller.db.ClearRunningProcesses()
return QObject.eventFilter(self, obj, event)
On 12/22/08 11:16 AM, "Iliya Gogolev" <iliya at realdice.com> wrote:
Yes, you are right. But I did it for checking if i can catch the event :) I
added mousePressEvent & mouse ReleaseEvent:
def mouseMoveEvent (self, p_event) :
print "CustomDockWidget mouseMoveEvent"
event.ignore()
def mouseReleaseEvent(self, event) :
print " CustomDockWidget mouseReleaseEvent"
event.ignore()
I also added the output(or breakpoint) and it did not work :) Actually I
want to catch the mouse move event in the parent - QMainWindow, when the
left mouse button pressed.
I want to make something similar to Widget Box of Qt Designer(left docked
side). For example, when user wants to add a button to a canvas, he select
it, the button layout is shown and then user can drag and drop it to the
canvas.
I think the way to implement it is: when one of the buttons of Widget Box
was selected (by pressing left mouse button and it's still pressed), cache
the mouse event in MainWindow and change a position of button layout entity.
-----Original Message-----
From: pyqt-bounces at riverbankcomputing.com
[mailto:pyqt-bounces at riverbankcomputing.com] On Behalf Of piotr malinski
Sent: Monday, December 22, 2008 5:38 PM
To: pyqt at riverbankcomputing.com
Subject: Re: [PyQt] QDockWidgetquestion
If you want to catch mouse events that happen on the docked widget
then yout CustomDockWidget must have such methods (def
mouseSomethingEvent(self, event)).
_______________________________________________
PyQt mailing list PyQt at riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
--
Internal Virus Database is out-of-date.
Checked by AVG.
Version: 7.5.549 / Virus Database: 270.9.10/1814 - Release Date: 11/26/2008
8:53 PM
Internal Virus Database is out-of-date.
Checked by AVG.
Version: 7.5.549 / Virus Database: 270.9.10/1814 - Release Date: 11/26/2008
8:53 PM
I tried it too. It did not help.
Sorry, I use QToolBox instead QTreeWidget, but there's no sense
From: Brian Kelley [mailto:kelley at eyesopen.com]
Sent: Monday, December 22, 2008 5:00 PM
To: Iliya Gogolev; pyqt at riverbankcomputing.com
Subject: Re: [PyQt] QDockWidgetquestion
QDockWidgets behave a little different than normal widgets. You need to
call "setWidget" to place a widget in a dock widget.
http://doc.trolltech.com/4.4/qdockwidget.html
Try:
CustomDockWidget(QDockWidget):
def __init__(self,parent):
QDockWidget.__init__(self, parent)
self.tree = QTreeWidget(self)
self.setWidget(self.tree)
On 12/22/08 9:54 AM, "Iliya Gogolev" <iliya at realdice.com> wrote:
Hi everyone!
I added QTreeWidget to QDockWidget and then added it to MainWindow by
addDockWidget function:
"""""""""""""""""""""""""""""""""""""""""""
CustomDockWidget(QDockWidget):
def __init__(self,parent):
QDockWidget.__init__(self, p_parent)
self.tree = QTreeWidget(self)
.
.
.
"""""""""""""""""""""""""""""""""""""""""""
class MainWindow(QMainWindow):
def __init__(self, p_parent = None):
QMainWindow.__init__(self, p_parent)
self.customWidget = CustomDockWidget(self)
self.addDockWidget (Qt.LeftDockWidgetArea, self.customWidget)
.
.
.
I'm trying to catch mouse event in MainWindow when I click on the
QTreeWidget and no success.
Any ideas?
Thanks
Internal Virus Database is out-of-date.
Checked by AVG.
Version: 7.5.549 / Virus Database: 270.9.10/1814 - Release Date: 11/26/2008
8:53 PM
_______________________________________________
PyQt mailing list PyQt at riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Internal Virus Database is out-of-date.
Checked by AVG.
Version: 7.5.549 / Virus Database: 270.9.10/1814 - Release Date: 11/26/2008
8:53 PM
Internal Virus Database is out-of-date.
Checked by AVG.
Version: 7.5.549 / Virus Database: 270.9.10/1814 - Release Date: 11/26/2008
8:53 PM
Internal Virus Database is out-of-date.
Checked by AVG.
Version: 7.5.549 / Virus Database: 270.9.10/1814 - Release Date: 11/26/2008
8:53 PM
_______________________________________________
PyQt mailing list PyQt at riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20081222/3cfa8eba/attachment-0001.html
More information about the PyQt
mailing list