Results 1 to 10 of 10

Thread: QTextEdit drag and drop problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default QTextEdit drag and drop problem

    Hi everyone! I'm completly new to qt4 and while writng a simple text editor I encountered a problem. I wanted to enable copying and pasting of images in my program. I found a sample code in QTextEdit documentation but I couldn't implement it in my program. I've been trying to figure this out but unfortunatelly without any success. Here is the code(I've pasted only a code which is responsible for drag and drop of images):
    Qt Code:
    1. //mainwindow.h
    2. class MainWindow : public QMainWindow, private Ui::MainWindow
    3. {
    4. Q_OBJECT
    5.  
    6. public:
    7. explicit MainWindow(QWidget *parent = 0);
    8. void insertFromMimeData( const QMimeData *source );
    9. bool canInsertFromMimeData( const QMimeData *source ) const;
    10.  
    11. //mainwindow.cpp
    12. bool MainWindow::canInsertFromMimeData( const QMimeData *source ) const
    13. {
    14. if (source->hasImage())
    15. return true;
    16. else
    17. return textEdit->canInsertFromMimeData(source);
    18. }
    19. void MainWindow::insertFromMimeData( const QMimeData *source )
    20. {
    21. if (source->hasImage())
    22. {
    23. QImage image = qvariant_cast<QImage>(source->imageData());
    24. QTextCursor cursor = textEdit->textCursor();
    25. QTextDocument *document = textEdit->document();
    26. document->addResource(QTextDocument::ImageResource, QUrl("image"), image);
    27. cursor.insertImage("image");
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 

    compiler says that this line
    return textEdit->canInsertFromMimeData(source);
    is wrong. I guess that it's a very simple mistake but I would be really grateful if someone could help me with it.
    Cheers!
    Last edited by high_flyer; 21st February 2011 at 10:13. Reason: code tags

Similar Threads

  1. QTextEdit Drag and Drop
    By guiQt in forum Qt Programming
    Replies: 5
    Last Post: 29th August 2010, 16:36
  2. Drag Drop Images from WebPage into QTextEdit
    By Nemo in forum Qt Programming
    Replies: 7
    Last Post: 15th December 2009, 09:35
  3. QTextEdit drag and drop
    By bunjee in forum Qt Programming
    Replies: 6
    Last Post: 7th February 2008, 16:41
  4. Drag and drop image into a QTextEdit ?
    By balazsbela in forum Qt Programming
    Replies: 1
    Last Post: 3rd September 2007, 14:47
  5. Drag n Drop problem
    By ScoOteR in forum Qt Programming
    Replies: 1
    Last Post: 21st March 2007, 10:52

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.