PDA

View Full Version : QGraphicsTextItem bug on mouse interaction?



mooreaa
3rd July 2008, 13:32
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?



#include <QApplication>
#include <QGraphicsRectItem>
#include <QGraphicsTextItem>
#include <QGraphicsScene>
#include <QGraphicsView>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsScene scene;

QGraphicsRectItem* rect = new QGraphicsRectItem(QRectF(25,25,120,80),0,&scene);
rect->setFlag(QGraphicsItem::ItemIsMovable, true);
rect->setFlag(QGraphicsItem::ItemIsSelectable, true);
rect->acceptHoverEvents();

QGraphicsTextItem* text = new QGraphicsTextItem("ABCDEFGHIJKLMNOP",rect,&scene);
text->setTextInteractionFlags( Qt::TextEditorInteraction );

QGraphicsView view;
view.setScene( &scene );
view.setDragMode( QGraphicsView::RubberBandDrag );
view.show();

return a.exec();
}


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!?!

patrik08
3rd July 2008, 15:46
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...



#include <QApplication>
#include <QGraphicsRectItem>
#include <QGraphicsTextItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QAbstractTextDocumentLayout>
#include <QBasicTimer>
class TextDia : public QGraphicsTextItem
{
Q_OBJECT

public:
TextDia::TextDia( const QString txt ,
QGraphicsItem *parent ,
QGraphicsScene *scene )
: QGraphicsTextItem(txt,parent,scene),
cursorTime(false),BackHightlight(QColor("#a6ffc7")) {
setBlinkingCursorEnabled(true);
BackHightlight.setAlpha(80);
}

QRectF boundingRect() const
{
return document()->documentLayout()->frameBoundingRect(document()->rootFrame());
}

void setBlinkingCursorEnabled(bool enable)
{
cursorTime = false; /* leave cursor not paint */
if (enable && QApplication::cursorFlashTime() > 0) {
cursorTimeLine.start( QApplication::cursorFlashTime() / 2,this);
setTextInteractionFlags ( Qt::TextEditorInteraction );
} else {
cursorTimeLine.stop();
setTextInteractionFlags ( Qt::NoTextInteraction );
}
}
void timerEvent(QTimerEvent *event)
{
if (event->timerId() == cursorTimeLine.timerId()) {
if (!cursorTime) {
cursorTime = true;
} else {
cursorTime = false;
}
update();
}
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(widget);
const int text_cursor_position = textCursor().position();
painter->save();
QAbstractTextDocumentLayout::PaintContext CTX;
CTX.selections;
painter->setClipRect(boundingRect(), Qt::IntersectClip);
if (cursorTime) {
CTX.cursorPosition = text_cursor_position;
} else {
CTX.cursorPosition = -1;
}
painter->setPen(Qt::NoPen);
CTX.clip = boundingRect();
painter->setBrush(BackHightlight);
painter->drawRect(boundingRect());
document()->documentLayout()->draw(painter,CTX);
painter->setPen(Qt::NoPen);
painter->restore();
}

QColor BackHightlight;
QBasicTimer cursorTimeLine;
bool cursorTime;
};
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsScene scene;
QGraphicsRectItem* rect = new QGraphicsRectItem(QRectF(25,25,120,80),0,&scene);
rect->setFlag(QGraphicsItem::ItemIsMovable, true);
rect->setFlag(QGraphicsItem::ItemIsSelectable, true);
rect->acceptHoverEvents();
TextDia* text = new TextDia("ABCDEFGHIJKLMNOP",rect,&scene);
QGraphicsView view;
view.setScene( &scene );
view.setDragMode( QGraphicsView::RubberBandDrag );
view.show();
return a.exec();
}

mooreaa
3rd July 2008, 23:14
No its not that i lose focus, its that even when I refocus, my mouse interaction does not work at all.

patrik08
4th July 2008, 07:29
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



void DiagramTextItem::focusOutEvent(QFocusEvent *event)
{
setTextInteractionFlags(Qt::NoTextInteraction);
emit lostFocus(this);
QGraphicsTextItem::focusOutEvent(event);
}
//! [2]

//! [5]
void DiagramTextItem::mouseDoubleClickEvent(QGraphicsSc eneMouseEvent *event)
{
if (textInteractionFlags() == Qt::NoTextInteraction)
setTextInteractionFlags(Qt::TextEditorInteraction) ;
QGraphicsTextItem::mouseDoubleClickEvent(event);
}




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