Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Closed]QListView : QDrag pixmap for custom widget.
Forum Updated to NodeBB v4.3 + New Features

[Closed]QListView : QDrag pixmap for custom widget.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sam
    wrote on last edited by
    #1

    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 :

    setDragEnabled(true);
    setAcceptDrops(true);
    setDragDropMode(QAbstractItemView::InternalMove);
    setDropIndicatorShown(true);
    setMovement(QListView::Snap);

    Which displays the list as :-
    !http://imageshack.us/a/img841/4781/capturemyj.png(listView)!

    But when I drag the list item , the drag pixmap is empty it just shows a blank image like (windows 7)
    !http://imageshack.us/a/img339/4898/capturesjz.png(image)!

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on last edited by
      #2

      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 ?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on last edited by
          #4

          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 ?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved