You are not logged in.

  • Login

1

Monday, January 22nd 2007, 6:51pm

PyQT: Drag&Drap + Doppelklick Aktion

Hallo QT Fans,
ich habe absichtlich eine Spur im C++ Forum gelassen, weil sich da naturgemäß mehr QT Entwickler rumtreiben und das Problem bestimmt keine Python Eigenheit ist.

Zu dem Problem: Ich bin gerade dabei mit Python und QT 3 einen Mailclient zu programmieren. Man soll die Mails mit Doppelklick öffnen oder mit einem Drag verschieben können.

Habe hier mal ein einfaches Beispiel erstellt:

Python Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from sys import argv
from qt import *
 
class DragDrop(QListView):
	def __init__(self, *args):
		QListView.__init__(self, *args)
		buttons = ["Drop Here1", "Drop Here2", "Drop Here3"]
 
		self.setAcceptDrops(1)
		self.setRootIsDecorated(True)
		self.addColumn("Column")
 
		for e in buttons:
			tmp = QListViewItem(self, e)
 
		QObject.connect(self, SIGNAL('pressed(QListViewItem *)'), self.startDrag)
		QObject.connect(self, SIGNAL('doubleClicked(QListViewItem *)'), self.double)
 
	def double(self):
		print "doppelklick"
		pass
 
	def dragEnterEvent(self, event):
		event.accept(QTextDrag.canDecode(event))
 
	def dropEvent(self, event):
		t=QString()
		QTextDrag.decode(event, t)
		pos = QPoint(event.pos().x(), event.pos().y() - self.header().height())
		item = self.itemAt(pos)
		if item is None:
			item = self		
		child = QListViewItem(item, t)
 
	def startDrag(self, lvi):
		if lvi is not None:
			d = QTextDrag(lvi.text(0), self)
			d.dragCopy()
 
 
if __name__ == '__main__':
	a = QApplication(argv)
	dragDrop = DragDrop()
	a.setMainWidget(dragDrop)
	dragDrop.setMinimumWidth(200)
	dragDrop.show()
	a.exec_loop()


Wenn ihr das mal laufen lasst, merkt ihr, dass der Doppelklick nur noch sehr schwierig auszulösen ist (weil bei minimalser Beweung die DragOperation startet)

Habt ihr eine Idee wie ich das lösen kann? Python liefert doch sonst alles mit ;-)

2

Sunday, March 25th 2007, 2:48pm

Ich habe mich übrigens für einen anderen Eventhandler entschieden.

Python Quellcode

1
2
QObject.connect(self, SIGNAL('pressed(QListViewItem *)'), self.startDrag)
QObject.connect(self, SIGNAL('selectionChanged ( QListViewItem * )'), self.double)

Similar threads

Social bookmarks