Results 1 to 7 of 7

Thread: Drag'n'Drop pixmap issue

  1. #1
    Join Date
    Apr 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Drag'n'Drop pixmap issue

    Hello,

    I'm currently trying to implement a drag'n'drop feature in a small program I'm developing.

    The feature is partially working, the item can be dragged from a widget to another, but as the drag begin, the QPixmap associated with it is completely black.

    Here's exactly what happens :

    GIFrecord_2015-04-28_160010.gif

    And here's the code where I start the drag event :

    Qt Code:
    1. void ActionButtonWidget::mouseMoveEvent(QMouseEvent * event)
    2. {
    3. QDrag *drag = new QDrag(this);
    4. QMimeData *mimeData = new QMimeData;
    5. QByteArray itemData;
    6. QDataStream dataStream(&itemData, QIODevice::WriteOnly);
    7. dataStream << * this;
    8. mimeData->setData("customWidget/actionButton",itemData);
    9. drag->setMimeData(mimeData);
    10. drag->setPixmap(QPixmap(*(this->pixmap()))); //This should be getting the pixmap from my widget right ?
    11. drag->setHotSpot(QPoint(drag->pixmap().width()/2,
    12. drag->pixmap().height()));
    13. Qt::DropAction dropAction = drag->exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    I don't understand why I can't get the result I want, I've even tried to load an external picture into the my QDrag pixmap, but the result is the same, always a black square.

    Does anybody have a clue on why it is behaving like this ?

    Thank you in advance for your answers !

    Regards,

    Azsde.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Drag'n'Drop pixmap issue

    Maybe you can verify that the pixmap is ok.
    E.g. have a local pixmap variable that you call save() on before you pass it to setPixmap().
    Then check the file.

    Cheers,
    _

  3. #3
    Join Date
    Apr 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Drag'n'Drop pixmap issue

    Quote Originally Posted by anda_skoa View Post
    Maybe you can verify that the pixmap is ok.
    E.g. have a local pixmap variable that you call save() on before you pass it to setPixmap().
    Then check the file.

    Cheers,
    _
    Hello and thank you for your answer.

    Saving the pixmap to a local file gets me a working PNG file that correspond to the pixmap.

    So I guess that my pixmap is fine, any other lead on why it is behaving like this ?

    Thank you in advance.

    Regards,

    Azsde.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Drag'n'Drop pixmap issue

    Try something very simple:
    - create a fixed size QPixmap, say 64x64
    - create a QPainter on it
    - use QPainter::fillRect() to fill it with a non-black color
    - use this pixmap instead of yours

    It if works, try your pixmap's size but use the rest of the approach.

    Cheers,
    _

  5. #5
    Join Date
    Apr 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Drag'n'Drop pixmap issue

    Quote Originally Posted by anda_skoa View Post
    Try something very simple:
    - create a fixed size QPixmap, say 64x64
    - create a QPainter on it
    - use QPainter::fillRect() to fill it with a non-black color
    - use this pixmap instead of yours

    It if works, try your pixmap's size but use the rest of the approach.

    Cheers,
    _
    Didn't have to try that, I tried the code I had on two other computers (Linux and Windows), and it works, no black square.
    So I guess the problem is caused by my computer.

    Thanks anyways

    Regards,

    Azsde.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Drag'n'Drop pixmap issue

    Could be something like color depth.
    E.g. image in 32bit depth, system not configured for 32bit depth, etc.

    Cheers,
    _

  7. #7
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drag'n'Drop pixmap issue

    check how the other drag images (not your application) on your OS . ex: Internet, some windows application or qt drag drop application . because i also faced some issue. my pixmap what i was dragginh looked completely blurred but on other PC it was fine . so i checked other application drag images and it also shows similar kind of result .. it may be a problem with your OS.
    "Behind every great fortune lies a crime" - Balzac

Similar Threads

  1. QGlWidget issue on drag and drop
    By drujma in forum Qt Programming
    Replies: 4
    Last Post: 26th July 2013, 09:30
  2. Replies: 1
    Last Post: 25th May 2011, 21:20
  3. Replies: 2
    Last Post: 13th October 2010, 21:51
  4. Creating a Pixmap for drag and drop
    By Cruz in forum Qt Programming
    Replies: 22
    Last Post: 20th January 2009, 14:51
  5. cursor pixmap during drag&drop
    By darksaga in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 15:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.