Results 1 to 10 of 10

Thread: QT 4.4 QGraphicsProxyWidget bridge Drag and Drop help

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QT 4.4 QGraphicsProxyWidget bridge Drag and Drop help

    I can not forward Drag and Drop is here more flag to set?

    QGraphicsProxyWidget not forward events to subwidged


    Qt Code:
    1. #include <QGraphicsScene>
    2. #include <QtGui>
    3. #include <QGraphicsProxyWidget>
    4. #include <QGraphicsTextItem>
    5. /* qt4.4 !! */
    6.  
    7.  
    8. class Xedit : public QTextBrowser
    9. {
    10. Q_OBJECT
    11. //
    12. public:
    13. Xedit::Xedit( QWidget* parent = 0 )
    14. : QTextBrowser(parent)
    15. {
    16. setAcceptDrops(true);
    17. }
    18. void dragEnterEvent(QDragEnterEvent *event)
    19. {
    20. qDebug() << "### dragEnterEvent ";
    21. /////event->acceptProposedAction();
    22. insertFromMimeData(event->mimeData());
    23. }
    24. void insertFromMimeData ( const QMimeData * source )
    25. {
    26. /* external paste drag */
    27. qDebug() << "### insertFromMimeData ";
    28. if ( source->formats().contains("text/html") ) {
    29. QString draghtml = source->html();
    30. QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(draghtml);
    31. textCursor().insertFragment(fragment);
    32. return;
    33. }
    34. if ( source->hasText() ) {
    35. textCursor().insertText(source->text());
    36. return;
    37. }
    38. }
    39.  
    40. };
    41.  
    42. int main(int argc, char *argv[])
    43. {
    44. QApplication a(argc, argv);
    45.  
    46. a.setOrganizationName("Dummy");
    47. a.setOrganizationDomain("dummy.com");
    48. a.setApplicationName("TestEventforward");
    49. /////Xedit *extendededit = new Xedit;
    50. ///////extendededit->show();
    51. QGraphicsView view(&scene);
    52. view.show();
    53. QWidget *editor = new QWidget;
    54. QGridLayout *grid = new QGridLayout(editor);
    55. Xedit *extendededit = new Xedit;
    56. extendededit->setReadOnly(false);
    57. extendededit->setOpenExternalLinks(false);
    58. grid->addWidget(extendededit, 0, 0, 1, 1);
    59. QGraphicsProxyWidget *proxy = scene.addWidget(editor);
    60. /* http://doc.trolltech.com/main-snapshot/qgraphicsproxywidget.html */
    61. proxy->setAcceptDrops( true );
    62. ////proxy->setAttribute( Qt::WA_AcceptDrops , true );
    63. QGraphicsTextItem *text = scene.addText("Helo world..!");
    64. text->setZValue(1.2);
    65. extendededit->setDocument(text->document());
    66.  
    67. proxy->show();
    68. proxy->setZValue(1.5);
    69. a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
    70. return a.exec();
    71. }
    72.  
    73. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    Last edited by patrik08; 26th March 2008 at 09:11.

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

    Default Re: QGraphicsProxyWidget forward Drag and Drop help

    What do you mean "forward drag and drop"? Does the view accept drops?

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsProxyWidget forward Drag and Drop help

    Quote Originally Posted by wysota View Post
    What do you mean "forward drag and drop"? Does the view accept drops?
    if i run only class Xedit : public QTextBrowser drag and drop work
    on QGraphicsProxyWidget inside QGraphicsScene i can edit and display correct,
    but not Drag inside text image or other ....
    the problem is only on drag and drop event... not comming in .

  4. #4
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsProxyWidget forward Drag and Drop help

    Quote Originally Posted by wysota View Post
    What do you mean "forward drag and drop"? Does the view accept drops?
    i not think that QGraphicsView must send all drag and drop event to his subitem?
    but it works ...
    i hope to not forward keyPressEvent and all other ...

    Qt Code:
    1. void XhtmlView::dragEnterEvent ( QDragEnterEvent * e )
    2. {
    3. /* DivDiagram *CurrentActive; only xhtml <div> tag */
    4. if (CurrentActive->id() > 0 && CurrentActive->ProxyBridgeEdit->isVisible()) {
    5. CurrentActive->AdvanceEdit->wtxt->insertFromMimeData(e->mimeData());
    6. return;
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QGraphicsProxyWidget forward Drag and Drop help

    But did you enable drops for the view?

  6. #6
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsProxyWidget forward Drag and Drop help

    Quote Originally Posted by wysota View Post
    But did you enable drops for the view?
    Yes ... but i like only drag drop on subitem QGraphicsProxyWidget an his QWidget
    the doc say : QGraphicsProxyWidget imo forum QTCLASS 4.4beta not found http://doc.trolltech.com/main-snapsh...oxywidget.html
    The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene.
    QGraphicsProxyWidget embeds any QWidget-based widget, for example, a QPushButton, QFontComboBox, or even QFileDialog, into QGraphicsScene. It forwards events between the two objects and translates between QWidget's integer-based geometry and QGraphicsWidget's qreal-based geometry. QGraphicsProxyWidget supports all core features of QWidget, including tab focus, keyboard input, Drag & Drop, and popups. You can also embed complex widgets, e.g., widgets with subwidgets.
    QGraphicsProxyWidget takes care of automatically embedding popup children of embedded widgets through creating a child proxy for each popup. This means that when an embedded QComboBox shows its popup list, a new QGraphicsProxyWidget is created automatically, embedding the popup, and positioning it correctly.
    I wand to build only a xhtml editor that processing div tag floating absolute and display it block or not...
    Attached Images Attached Images

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

    Default Re: QGraphicsProxyWidget forward Drag and Drop help

    It could be D&D related event passing through the proxy has not yet been implemented. We are talking about beta software here.

  8. #8
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsProxyWidget forward Drag and Drop help

    Quote Originally Posted by wysota View Post
    It could be D&D related event passing through the proxy has not yet been implemented. We are talking about beta software here.
    you know another way to display inside QGraphicsView / QGraphicsTextItem an exdended
    xhtml editor? not beta?

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

    Default Re: QGraphicsProxyWidget forward Drag and Drop help

    Implement a custom QGraphicsItem.

  10. The following user says thank you to wysota for this useful post:

    patrik08 (27th March 2008)

  11. #10
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsProxyWidget forward Drag and Drop help

    Quote Originally Posted by wysota View Post
    Implement a custom QGraphicsItem.

    Now is running i drag drop from QGraphicsView and send to QGraphicsTextItem proxie..
    to insert image or so..
    And QGraphicsTextItem become 33 line to handle text from parent QAction on a simple way..

    Qt Code:
    1. void DivDiagram::TextHandler()
    2. {
    3. QColor col;
    4. QAction *invoice = qobject_cast<QAction *>(sender());
    5. const double cases = invoice->data().toDouble();
    6. QTextCursor c = QGraphicsTextItem::textCursor();
    7. QTextCharFormat format = c.charFormat();
    8. QFont f = format.font();
    9. if (cases == 0.01) {
    10. f.setBold(true);
    11. } else if (cases == 0.02) {
    12. f.setItalic(true);
    13. } else if (cases == 0.03) {
    14. f.setOverline(true);
    15. } else if (cases == 0.04) {
    16. f.setUnderline(true);
    17. } else if (cases == 0.05) {
    18. f.setStrikeOut(true);
    19. } else if (cases == 0.06) {
    20. col = QColorDialog::getRgba();
    21. if (!col.isValid()) {
    22. return;
    23. }
    24. format.setForeground(QBrush(col));
    25. } else if (cases == 0.07) {
    26. col = QColorDialog::getRgba();
    27. if (!col.isValid()) {
    28. return;
    29. }
    30. format.setBackground(QBrush(col));
    31. } else if (cases > 3) {
    32. f.setPointSizeF(cases);
    33. } else {
    34. return;
    35. }
    36. format.setFont(f);
    37. c.setCharFormat(format);
    38. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Drag & drop with model/view (Qt4)
    By yogeshm02 in forum Qt Programming
    Replies: 16
    Last Post: 19th September 2011, 20:36
  2. Problem with a cursor during Drag and Drop
    By mtrpoland in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2007, 15:46
  3. Replies: 7
    Last Post: 8th September 2006, 16:19
  4. Drag and drop outside the application
    By jpn in forum Newbie
    Replies: 7
    Last Post: 27th August 2006, 15:37
  5. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 16:41

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.