[Development] QtQuick: Drag pixmap

Alan Alpert 416365416c at gmail.com
Wed Jan 29 00:19:04 CET 2014


On Tue, Jan 28, 2014 at 3:02 PM, Mark Gaiser <markg85 at gmail.com> wrote:
> On Tue, Jan 28, 2014 at 11:32 PM, Alan Alpert <416365416c at gmail.com> wrote:
>> On Tue, Jan 28, 2014 at 1:25 PM, Mark Gaiser <markg85 at gmail.com> wrote:
>>> On Tue, Jan 28, 2014 at 8:28 PM, Alan Alpert <416365416c at gmail.com> wrote:
>>>> On Wed, Jan 22, 2014 at 10:42 AM, Mark Gaiser <markg85 at gmail.com> wrote:
>>>>> On Wed, Jan 22, 2014 at 12:11 AM, Fabien Castan <fabcastan at gmail.com> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> Qt 5.2 adds the possibility to use drag&drop from/to external applications.
>>>>>> To allows to drag an item from QML to an external application, we can't
>>>>>> simply set a target item, because we want to see this item ouside of the qml
>>>>>> window.
>>>>>> In Qt, we could set a pixmap on drag events:
>>>>>> http://qt-project.org/doc/qt-4.8/qdrag.html#setPixmap
>>>>>>
>>>>>> I don't see something like that in QtQuick (Qt 5.2):
>>>>>> http://qt-project.org/doc/qt-5/qml-qtquick-drag.html
>>>>>>
>>>>>> Is there a solution to do such thing in pure QML?
>>>>>>
>>>>>> Regards,
>>>>>> Fabien
>>>>>
>>>>> While browsing through the code (qquickdrag.cpp) i found these two
>>>>> commented lines:
>>>>>     // TODO: how to handle drag image?
>>>>>     // drag->setPixmap(iconPixmap);
>>>>>
>>>>> Along with that no more function for "setPixmap" that is exposed to QML.
>>>>> That makes me fear that the setPixmap property is not there anymore.
>>>>>
>>>>> Odd, since it would be an API break which i can't really imagine from Qt.
>>>>>
>>>>> I hope someone else more knowledgeable in this area can chime in?
>>>>
>>>> Use of direct QPixmaps in QML is discouraged, because there's no real
>>>> way to manage the memory of the pointer. If there were a QObject or
>>>> QJSValue wrapper around QPixmap then a setPixmap could be added,
>>>> similar to the setPixmap in QDrag (although not actually accepting a
>>>> QPixmap type).
>>>>
>>>> So without a good solution handy, that part has been left "for later".
>>>
>>> Alan, would it be possible to use a Image{...} item as "pixmap"?
>>> Yes, right now it's not possible, but just as an idea for a workable
>>> implementation.
>>
>> Not really. The Image element contains much more than just the pixmap,
>> such as positioning and rendering hints, so it's both too heavy and
>> most of the properties would be lost. We'd ideally like a lightweight
>> JS wrapper which just takes a URL (possibly one from an image
>> provider), so long as it can be used declaratively.
>
> Ahh, didn't know that.
>
> So if we continue that idea, would it make sense to re-create the
> Image{} component in two parts? One for representing the actual image
> data, one for representing is's place in the QML app.
>
> Lets call the one just representing the image data "ImageData {}". It
> only knows how to represent a image based from an url or image
> provider.
> The Image{} component that inherits from ImageData{} and adds whatever
> it needs to be on par with the current Image{} component.
>
> Would an approach like that make sense?
> just thinking out loud now :)

Thinking out loud, I'd do something more like the Sprite classes.
There's a Sprite{} which encapsulates logical data, a SpriteSequence{}
for playing and transitioning between sprites, and a convenience
AnimatedSprite{} which is like a Sprite that draws itself (with some
rendering options added). So Image{} would stay the same, inherit from
ImageData{} in a conceptual sense, but there would be a more basic
ImageData{} which is used by other elements.

Assuming that there's enough complexity in ImageData to be worth a
QObject type (Sprite has a lot of properties:
https://qt-project.org/doc/qt-5/qml-qtquick-sprite.html ) , Otherwise
we should just add a basic type with a (possibly implicit) URL
constructor, as long as it's JS reference counted.

The other thing I'm thinking of is that a C++ API would actually be
useful here. Dropping down to C++ isn't the real problem here, that's
pretty easy to do with QML. Except that you can't take an existing QML
scene and just pass in the pixmap from C++, because it can't go
through QML for the above reference reasons. The most convenient way
then would be to get the QML item reference and pass the pixmap wholly
in C++, but we can't currently add public C++ API to QtQuick elements.

--
Alan Alpert



More information about the Development mailing list