Date: Sun, 29 Apr 2007 17:43:53 +0200
From: Hans-Peter Jansen <[EMAIL PROTECTED]>
Subject: Re: [PyQt] question re Atext drag and drop in PyQt3
To: [email protected]
Message-ID: <[EMAIL PROTECTED]>
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 <[EMAIL PROTECTED]>
To: Tony Willis <[EMAIL PROTECTED]>
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   [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