[PyQt] question re Atext drag and drop in PyQt3

Tony Willis Tony.Willis at nrc-cnrc.gc.ca
Mon Apr 30 22:57:48 BST 2007


> Date: Sun, 29 Apr 2007 17:43:53 +0200
> From: Hans-Peter Jansen <hpj at urpla.net>
> Subject: Re: [PyQt] question re Atext drag and drop in PyQt3
> To: pyqt at riverbankcomputing.com
> Message-ID: <200704291743.53518.hpj at urpla.net>
> Content-Type: text/plain;  charset="iso-8859-1"

> Am Freitag, 27. April 2007 23:43 schrieb Tony Willis:
> > 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'.

> Without looking into your code, have you considered using Decimals, and send
> the str() versions? Sure, they're not the fastest types in town, but unless
> you're not sending more than a few thousands of values on a decent system,
> they should do well without the usual float pains.

> Pete

Yes, I was considering doing what you suggest, but then one of the
people I work with came up with the following suggestion which works
even better.

Cheers

Tony

> Date: Sun, 29 Apr 2007 17:13:04 +0200
> From: Oleg M. Smirnov <smirnov at astron.nl>
> To: Tony Willis <Tony.Willis at nrc-cnrc.gc.ca>
> Subject: Re: question re text drag and drop in PyQt3 (fwd)
> 
> 
> Hi Tony --
> 
> I never bothered with encoding actual data in the drag object. I find it
> easier to just send around string keys (or "commands", if you like), and on
> the receiving end directly calling a method on the drag source widget in
> response to commands. E.g. in the source widget you do:

> QTextDrag("copyRange",self);
> 
> and then in the destination widget:
> 
> 
>   def dropEvent (self,ev):
>     command = QString();
>     if QTextDrag.decode(ev,command):
>       if str(command) == "copyRange":
>         rng = ev.source().get_data_range();
>
>of course your source widget has to implement get_data_range(), but that's
>not difficult.

>Cheers,
>Oleg

-- 
___________
Tony Willis
National Research Council   Tony.Willis at nrc-cnrc.gc.ca
Box 248                     (250)493-2277
Penticton, BC  V2A 6J9      fax: 493-7767
Government of Canada        Gouvernement du Canada



More information about the PyQt mailing list