Results 1 to 6 of 6

Thread: Drag and Drop QTableWidget and QTableView

  1. #1
    Join Date
    Feb 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question Drag and Drop QTableWidget and QTableView

    Hi,

    I am new to Qt.

    I have to implement Drag and Drop feature on QTableWidget and QTableView in my application. I need to drag the table and drop it into another application such as ms-word.

    I have already implemented something which works partially...in the sense that, when i drag the table and drop it in ms-word, it gets copied there, but the problem is, if the table contains any scroll bars, the cells behind the scroll bars dont get copied, only that part of the table which is visible gets copied into ms-word.

    The code which i use to achieve this is,

    QDrag *drag = new QDrag(this);
    QMimeData *mimeData = new QMimeData;

    QPixmap img = QPixmap::grabWidget(this);

    mimeData->setImageData(img.toImage());
    drag->setMimeData(mimeData);

    I have subclassed QTableWidget and QTableView and implemented the above code in the mouseMoveEvent.

    I was hoping the grabWidget() would get the entire TableWidget.

    I think the mimeData has to be used properly, but I am not sure how to proceed further on this.

    Any help would be very much appreciated.
    Thanks and Regards.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag and Drop QTableWidget and QTableView

    Are you sure you want to copy an image of the table? Maybe it's better to copy the contents instead? By the way, QTableWidget and QAbstractItemModel have dedicated methods for handing drags.

  3. #3
    Join Date
    Feb 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag and Drop QTableWidget and QTableView

    Hi,

    My requirement is to get the entire table into ms-word, when i do a drag and drop....even the cells hidden behind the scroll bars.

    I am not sure whether to copy as an image or its contents.

    Thanks.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag and Drop QTableWidget and QTableView

    If you want to edit or format the table, I really suggest you copy the contents.

  5. #5
    Join Date
    Feb 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag and Drop QTableWidget and QTableView

    Hi,

    Actually, I would like to have the image of the table which will ne non-editable along with its header's also visible in the image.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag and Drop QTableWidget and QTableView

    In that case you can prepare a pixmap large enough to hold the whole table and use QWidget::render() to render the table on it.

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.