Can't you use QPainter to draw text on the pixmap, before you pass it to QDrag ?
Can't you use QPainter to draw text on the pixmap, before you pass it to QDrag ?
I tried that with:
Qt Code:To copy to clipboard, switch view to plain text mode
But I still don't get it!
Well, you are trying to draw on a null pixmap...
Initialize the pixmap with non-zero size, fill it with background color, then draw text.
qlands (27th September 2011)
ok.
Almost there, now I get a white pixmap with the appropriate size but without the text.
Qt Code:
pixmap.fill(); paint.drawText(met.boundingRect("Some text here"),Qt::AlignLeft,"Some text here");To copy to clipboard, switch view to plain text mode
I reckon painter is not starting to draw in a good position.
Yep! It was the Y... it must be negative
Qt Code:
paint.drawText(0,0-rect.y(),"Some text here");To copy to clipboard, switch view to plain text mode
Thanks for your help.
Last edited by qlands; 27th September 2011 at 12:37.
When you create the QTreeWidgetItem, do not set the text or icon.
Instead, create a QWidget that contains 2 QLabels (one for the icon, one for the text), then use the QTreeWidget::setItemWidget method to associate the QWidget with the QTreeWidgetItem.
When you see the mousePressEvent that starts the drag, get the QTreeWidgetItem *drag_item that's under the mouse by calling QTreeWidget::itemAt(event->pos()).
When creating the QDrag, create the pixmap by doing something like this:
QWidget *w = itemWidget(drag_item,0);
QPixmap pixmap(w->size());
w->render(&pixmap);
QDrag *drag = new QDrag;
drag->setPixmap(pixmap);
Bookmarks