Results 1 to 4 of 4

Thread: QGraphicsTextItem bug on mouse interaction?

  1. #1

    Default QGraphicsTextItem bug on mouse interaction?

    I found a fairly big bug with QGraphicsTextItem. Maybe someone can reproduce before I submit a bug report? Also where do I report bugs again?

    Qt Code:
    1. #include <QApplication>
    2. #include <QGraphicsRectItem>
    3. #include <QGraphicsTextItem>
    4. #include <QGraphicsScene>
    5. #include <QGraphicsView>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10.  
    11. QGraphicsRectItem* rect = new QGraphicsRectItem(QRectF(25,25,120,80),0,&scene);
    12. rect->setFlag(QGraphicsItem::ItemIsMovable, true);
    13. rect->setFlag(QGraphicsItem::ItemIsSelectable, true);
    14. rect->acceptHoverEvents();
    15.  
    16. QGraphicsTextItem* text = new QGraphicsTextItem("ABCDEFGHIJKLMNOP",rect,&scene);
    17. text->setTextInteractionFlags( Qt::TextEditorInteraction );
    18.  
    19. view.setScene( &scene );
    20. view.setDragMode( QGraphicsView::RubberBandDrag );
    21. view.show();
    22.  
    23. return a.exec();
    24. }
    To copy to clipboard, switch view to plain text mode 

    Run, select some text, now click on the dotted border of the edit text item.

    Mouse interaction stops working.

    I tried subclassing it and tried a few things with onmousepress events and such but wasn't able to fix this sucker.

    Can someone else confirm this? And possibly a workaround!?!
    Last edited by mooreaa; 3rd July 2008 at 13:47.

  2. #2
    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: QGraphicsTextItem bug on mouse interaction?

    Quote Originally Posted by mooreaa View Post
    I found a fairly big bug with QGraphicsTextItem. Maybe someone can reproduce before I submit a bug report? Also where do I report bugs again?
    Mouse interaction stops working.
    I tried subclassing it and tried a few things with onmousepress events and such but wasn't able to fix this sucker.

    Can someone else confirm this? And possibly a workaround!?!
    this is not a bug if focus is lost the cursor not repaint....

    if you like permanent edit and cursor blink test this...

    Qt Code:
    1. #include <QApplication>
    2. #include <QGraphicsRectItem>
    3. #include <QGraphicsTextItem>
    4. #include <QGraphicsScene>
    5. #include <QGraphicsView>
    6. #include <QAbstractTextDocumentLayout>
    7. #include <QBasicTimer>
    8. class TextDia : public QGraphicsTextItem
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. TextDia::TextDia( const QString txt ,
    14. QGraphicsItem *parent ,
    15. QGraphicsScene *scene )
    16. : QGraphicsTextItem(txt,parent,scene),
    17. cursorTime(false),BackHightlight(QColor("#a6ffc7")) {
    18. setBlinkingCursorEnabled(true);
    19. BackHightlight.setAlpha(80);
    20. }
    21.  
    22. QRectF boundingRect() const
    23. {
    24. return document()->documentLayout()->frameBoundingRect(document()->rootFrame());
    25. }
    26.  
    27. void setBlinkingCursorEnabled(bool enable)
    28. {
    29. cursorTime = false; /* leave cursor not paint */
    30. if (enable && QApplication::cursorFlashTime() > 0) {
    31. cursorTimeLine.start( QApplication::cursorFlashTime() / 2,this);
    32. setTextInteractionFlags ( Qt::TextEditorInteraction );
    33. } else {
    34. cursorTimeLine.stop();
    35. setTextInteractionFlags ( Qt::NoTextInteraction );
    36. }
    37. }
    38. void timerEvent(QTimerEvent *event)
    39. {
    40. if (event->timerId() == cursorTimeLine.timerId()) {
    41. if (!cursorTime) {
    42. cursorTime = true;
    43. } else {
    44. cursorTime = false;
    45. }
    46. update();
    47. }
    48. }
    49. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
    50. QWidget *widget)
    51. {
    52. Q_UNUSED(widget);
    53. const int text_cursor_position = textCursor().position();
    54. painter->save();
    55. QAbstractTextDocumentLayout::PaintContext CTX;
    56. CTX.selections;
    57. painter->setClipRect(boundingRect(), Qt::IntersectClip);
    58. if (cursorTime) {
    59. CTX.cursorPosition = text_cursor_position;
    60. } else {
    61. CTX.cursorPosition = -1;
    62. }
    63. painter->setPen(Qt::NoPen);
    64. CTX.clip = boundingRect();
    65. painter->setBrush(BackHightlight);
    66. painter->drawRect(boundingRect());
    67. document()->documentLayout()->draw(painter,CTX);
    68. painter->setPen(Qt::NoPen);
    69. painter->restore();
    70. }
    71.  
    72. QColor BackHightlight;
    73. QBasicTimer cursorTimeLine;
    74. bool cursorTime;
    75. };
    76. #include "main.moc"
    77. int main(int argc, char *argv[])
    78. {
    79. QApplication a(argc, argv);
    80. QGraphicsRectItem* rect = new QGraphicsRectItem(QRectF(25,25,120,80),0,&scene);
    81. rect->setFlag(QGraphicsItem::ItemIsMovable, true);
    82. rect->setFlag(QGraphicsItem::ItemIsSelectable, true);
    83. rect->acceptHoverEvents();
    84. TextDia* text = new TextDia("ABCDEFGHIJKLMNOP",rect,&scene);
    85. view.setScene( &scene );
    86. view.setDragMode( QGraphicsView::RubberBandDrag );
    87. view.show();
    88. return a.exec();
    89. }
    To copy to clipboard, switch view to plain text mode 

  3. #3

    Default Re: QGraphicsTextItem bug on mouse interaction?

    No its not that i lose focus, its that even when I refocus, my mouse interaction does not work at all.

  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: QGraphicsTextItem bug on mouse interaction?

    Quote Originally Posted by mooreaa View Post
    No its not that i lose focus, its that even when I refocus, my mouse interaction does not work at all.
    if I refocus my mouse continue to edit and blink... on your code

    Install qt4.4.0 .....

    show /Qt/4.4.0_src/examples/graphicsview/diagramscene having a swap to move && edittext

    Qt Code:
    1. void DiagramTextItem::focusOutEvent(QFocusEvent *event)
    2. {
    3. setTextInteractionFlags(Qt::NoTextInteraction);
    4. emit lostFocus(this);
    5. QGraphicsTextItem::focusOutEvent(event);
    6. }
    7. //! [2]
    8.  
    9. //! [5]
    10. void DiagramTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
    11. {
    12. if (textInteractionFlags() == Qt::NoTextInteraction)
    13. setTextInteractionFlags(Qt::TextEditorInteraction);
    14. QGraphicsTextItem::mouseDoubleClickEvent(event);
    15. }
    To copy to clipboard, switch view to plain text mode 


    IMO my work:
    http://www.qt-apps.org/content/show....?content=80234

Similar Threads

  1. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 06:13
  2. Replies: 2
    Last Post: 24th July 2006, 18:36
  3. QStackerWidget and mouse events
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 19:25

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.