Results 1 to 3 of 3

Thread: DropIndicator is empty when moving an item from QTreeWidget to QTableWidget

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Davao City, Philippines
    Posts
    77
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question DropIndicator is empty when moving an item from QTreeWidget to QTableWidget

    Good am!

    I have just startet to deal with DnD and I got it working already.

    But there is one problem left: The DropIndicator is empty! Means, there is the '+'-sign and a small empty square only while copying an item.

    I guess, it's not not a big thing but I was not able to find it out by myself.

    Here is some code:

    tablewidget.h
    Qt Code:
    1. class TableWidget : public QTableWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. TableWidget( QWidget *parent = 0 );
    6. protected:
    7. void dropEvent( QDropEvent *event );
    8. void dragEnterEvent( QDragEnterEvent *event );
    9. void dragMoveEvent( QDragMoveEvent* event );
    10. private:
    11. TableWidget *tableWidget;
    12. };
    To copy to clipboard, switch view to plain text mode 

    tablewidget.cpp
    Qt Code:
    1. #include "tablewidget.h"
    2.  
    3. TableWidget::TableWidget( QWidget *parent )
    4. : QTableWidget( parent )
    5. {
    6. setAcceptDrops( true );
    7. }
    8.  
    9. void TableWidget::dropEvent( QDropEvent *event )
    10. {
    11. itemAt( event->pos() )->setText( event->mimeData()->text() );
    12. event->acceptProposedAction();
    13. }
    14.  
    15. void TableWidget::dragEnterEvent( QDragEnterEvent *event )
    16. {
    17. event->acceptProposedAction();
    18. }
    19.  
    20. void TableWidget::dragMoveEvent( QDragMoveEvent* event )
    21. {
    22. event->accept();
    23. }
    To copy to clipboard, switch view to plain text mode 

    treewidget.h
    Qt Code:
    1. class TreeWidget : public QTreeWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. TreeWidget( QWidget *parent = 0 );
    7. protected:
    8. void mouseMoveEvent( QMouseEvent *event );
    9. private:
    10. TreeWidget *treeWidget;
    11. };
    To copy to clipboard, switch view to plain text mode 

    treewidget.cpp

    Qt Code:
    1. TreeWidget::TreeWidget( QWidget *parent )
    2. : QTreeWidget( parent )
    3. {
    4. setDragEnabled( true );
    5. }
    6.  
    7. void TreeWidget::mouseMoveEvent( QMouseEvent *event )
    8. {
    9. if ( ! ( event->buttons() & Qt::LeftButton ) )
    10. return;
    11.  
    12. if ( currentItem() == NULL )
    13. return;
    14.  
    15. QDrag *drag = new QDrag( this );
    16. QMimeData *mimeData = new QMimeData;
    17.  
    18. mimeData->setText( currentItem()->text( 0 ) );
    19. drag->setMimeData( mimeData );
    20.  
    21. drag->start( Qt::CopyAction | Qt::MoveAction );
    22. }
    To copy to clipboard, switch view to plain text mode 

    Any idea what's missing?
    Last edited by gboelter; 8th October 2010 at 07:35. Reason: spelling corrections

Similar Threads

  1. Getting an item from an empty table widget
    By ProTonS in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2009, 02:24
  2. (PyQt) moving items within a QTreeWidget
    By calireno in forum Newbie
    Replies: 0
    Last Post: 12th November 2008, 03:33
  3. moving one graphical item over other item...
    By salmanmanekia in forum Qt Programming
    Replies: 36
    Last Post: 3rd July 2008, 07:59
  4. QTableWidget test if the cell or item are empty
    By jaca in forum Qt Programming
    Replies: 2
    Last Post: 2nd January 2008, 14:47
  5. Spanned Item Spacing on Empty Columns
    By giverson in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2007, 22:10

Tags for this Thread

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.