I hope that someone can help me with the following. I'm attempting
to drag and drop some floating point numbers from one widget to
another with PyQt3. The easiest way to do the dragging would appear to be with the QTextDrag object. So I convert my floating point numbers
to a python string  via the 'struct' module 'pack' method - see
line 30 in the 'startDrag' callback of the following script.

However when I unpack in the 'dropEvent' callback I get incorrect values
(1.0569533721655998e-307, 1.7246384989945063e-307) instead of
the expected (1.2, 3.5). I'm obviously screwing up some ascii / unicode / binary translation thingy somewhere, as the
methods work ok when I drag straight ascii text such as 'abcd_xyz'
i.e. in that case the QTextDrag.decode call in line 19 will give text as 'abcd_xyz'.

Thanks for any advice on this.

Cheers

Tony
---------------------------

#!/usr/bin/env python
from sys import argv
from qt import *
from struct import *

class DropDemo(QListView):
    def __init__(self,parent=None,name=None):
        QListView.__init__(self,parent,name)
        self.setAcceptDrops(True)
        self.setGeometry(10,10,100,60)

    def dragEnterEvent(self, event):
        print 'in dragEnterEvent'
        event.accept(QTextDrag.canDecode(event))

    def dropEvent(self, event):
        text= QString()
        if QTextDrag.decode(event, text):
          result = unpack('dd', text)
          print 'dropped ', result
#dropped  (1.0569533721655998e-307, 1.7246384989945063e-307)
        else:
          print 'decode failure'

    def mouseMoveEvent(self, event):
        self.startDrag()

    def startDrag(self):
        pack_str = pack('dd', 1.2, 3.5)
        d = QTextDrag(pack_str, self)
# dragging the following works
#       d = QTextDrag('abcd_xyz', self)
        .dragCopy()

if __name__ == '__main__':
    a = QApplication(argv)
    w = DropDemo()
    w.setCaption("Drag and Drop Test")
    w.resize(120,80)
    a.setMainWidget(w)
    w.show()
    a.exec_loop()
##########################


--
___________
Tony Willis
National Research Council   [EMAIL PROTECTED]
Box 248                     (250)493-2277
Penticton, BC  V2A 6J9      fax: 493-7767
Government of Canada        Gouvernement du Canada

_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to