[Closed]QListView : QDrag pixmap for custom widget.

  • I added a custom widget to my listview using QListView::setIndexWidget(), which works fine and displays the custom widget as items in the listView, Apart from this I added an additional internal drag and drop to the listview using :


    Which displays the list as :-

    But when I drag the list item , the drag pixmap is empty it just shows a blank image like (windows 7)

    But i want to show the pixmap of the selected Item, Also if i drop the item then at that particular index the item is blank.

    Note : I am just using internal drag and drop. I have not implemented
    @void dragEnterEvent(QDragEnterEvent *event);
    void dragMoveEvent(QDragMoveEvent *event);
    void dropEvent(QDropEvent *event);
    void startDrag(Qt::DropActions supportedActions);@

    If the former does not work then i think i need to implement using the above functions.

  • Ok so now I am trying to implement the drag and drop using the above methods. Is there any possibility to grab/get the pixmap of the selected item in the QListView ?

  • That grabbing is what the default implementation already does. However, what you are doing is overlaying the default list items with a widget. So, you'll need to grab the pixmap from the widget. Lucky for you, QWidget has the render() method that allows you to render a widget on any paintdevice or using any QPainter...

  • Thanks Andre,

    But how to use it and where to use it , I am adding the widets to the listView using setIndexWidget().
    I also have a listViewDelegate subclassed from QStyledItemDelegate , Should I render the widget in the delegate ?

  • Can't you get a pointer to the widget using indexWidget()?
    You do not need to render the widget in the delegate, I think, though it might work as a workaround to set a render of the widget as an image in the displayRole of the list view. That's a hack though, not a solution.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.