[Qt-interest] Howto make QGraphicsTextItem draggable?
Wilhelm
wilhelm.meier at fh-kl.de
Thu Dec 31 07:19:26 CET 2009
Hi,
I want to make a QGraphicsTextItem drag and droppable AND still moveable
like the normal behaviour if I set QGraphicsItem::ItemIsMovable (see
below). Additionally I want to have the original text drawn while the
drag is active, so I tried to set the drag pixmap. But if I try to use a
painter to draw the item onto a pixmap, the application crashes with a
segfault (if you uncomment the commented codelines below).
What am I doing wrong here?
TextItem::TextItem(){
setFlag(QGraphicsItem::ItemIsMovable);
setFlag(QGraphicsItem::ItemIsSelectable);
}
void TextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event){
qDebug() << __func__ << event->pos();
QMimeData* mData = new QMimeData();
mData->setText("test");
QDrag* drag = new QDrag(event->widget());
drag->setMimeData(mData);
QPixmap pixmap(boundingRect().size().toSize());
pixmap.fill(Qt::blue);
QPainter painter(&pixmap);
// paint(&painter, 0, 0);
// painter.end();
drag->setPixmap(pixmap);
drag->exec();
}
--
Wilhelm
More information about the Qt-interest-old
mailing list