PDA

View Full Version : dragging



mickey
10th March 2006, 13:07
Hi,
I'm trying drag (and drop) of a text insert in a qlabel. But I see that drag event isn't called. Why? (maybe beacause on mywidget starts mouseMoveEvent also?)
Thanks


MyWidget::MyWidget( QWidget *parent, const char *name, const QGLWidget* shareWidget)
: QGLWidget ( parent, name, shareWidget) {

this->setAcceptDrops(true);
label = new QLabel("prove", this);
}

void MyWidget::startDrag() {
printf("start drag\n");
QDragObject *d = new QTextDrag (this->label->text(), this);
d->dragCopy();
//do NOT delete d
}

void MyWidget::dragEnterEvent(QDragEnterEvent* event) {
printf("start drag enter event\n");
event->accept(QTextDrag::canDecode(event) || QImageDrag::canDecode(event));
}

void MyWidget::dropEvent(QDropEvent* event) {
printf("start drop event\n");
QImage image;
QString text;

if (QImageDrag::decode(event, image)) {
//insertImageAt(image, event->pos());
}
else if (QTextDrag::decode(event, text)) {
//insertTextAt(text, event->pos());
}
}

McToo
10th March 2006, 15:20
If I understand, you are trying to drag/drop onto a QLabel? QLabel does not handle drag/drop events.

QLabel is derived from QFrame which is derived from QWidget. QWidget handles the drag/drop events, but the functions are protected, so they are not visible in QLabel.

If you want drag/drop, don't use the QLabel - just override the paint function of mywidget to output the text.

HTH

McToo

mickey
10th March 2006, 15:32
Sorry, I'm trying to dragging the text inside a QLabel onto "still undefined".
To do this I put a QLabel with text onto myWidget (GL) and I code this:


void MyWidget::startDrag() {
printf("start drag\n");
QDragObject *d = new QTextDrag (this->label->text(), this);
d->dragCopy();
//do NOT delete d
}
but doesn't start. What can I insert onto myWidget to see only drag effect?
Thanks

McToo
10th March 2006, 16:01
Make mywidget paint the text, not QLabel.

You'd have to get rid of the label=new QLabel in the mywidget constructor.

Override
QWidget::paint in mywidget to output whatever text you wanted.

Then you would see the startDrag function called.

HTH

McToo

mickey
10th March 2006, 18:54
I don't understand. I must to do drawText("some text")? my paintGL() draw openGL object.....Does it to be a GL text? I have also write on mywidget with renderText("some").....But I can't drag it; don't drag!

McToo
11th March 2006, 01:26
Sorry, just realised mywidget is derived from QGLWidget, :o so you have the same problem with mywidget as with QLabel, i.e. you don't have access to the protected drag/drop member functions from QWidget. Forget my last post, it was drivel :o

Try creating a seperate QWidget derived class that will have the same screen placement and geometry as mywidget, but sits above it in the z order (use raise() stackUnder()) and is transparent setWindowOpacity() (Win & Mac only) - don't know how to make windows transparent in X. This then acts as a drag/drop target for mywidget.

There's probably a neater way...

McToo