Re: QTextEdit drag and drop
What exactly are you creating and deleting? The text edit widget? What is your purpose?
Re: QTextEdit drag and drop
Ok,
I have a custom "bubble widget" like the one in an iChat conversation.
When hoovering the widget with the mouse I'm replacing painted text by a QTextEdit to get the "copy", "open links" (etc) functionnalities.
Only problem is when drag and dropping a block of text out of the bubble it crashes because the leave event deletes my QTextEdit.
So my question is :
- Is there a way to disable Drag and drop on a QTextEdit.
- Or do you have a better approach for doing it.
Re: QTextEdit drag and drop
Try using a QLabel and use QLabel::setTextInteractionFlags() with Qt::TextBrowserInteraction. If it doesn't give you what you want, use QTextBrowser or QTextEdit instead but don't delete it when leaving its borders - instead remove its frame so that it looks like an ordinary text. Or you can even have the frame removed all the time. QTextEdit has QFrame as its ancesstor so you can manipulate its frame shape.
Re: QTextEdit drag and drop
Code:
//=============================================================================
//=============================================================================
/* virtual */ void ZeParagraphWidget
::enterEvent(QEvent * event
) {
if (mTextBrowser)
{
mTextBrowser->document()->deleteLater();
mTextBrowser->deleteLater();
mTextBrowser = NULL;
}
mTextBrowser->setDocument(mTextDocument->clone());
mTextBrowser->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
mTextBrowser->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
mTextBrowser->setStyle(ZeStyle::get());
mTextBrowser->setOpenExternalLinks(true);
mTextBrowser->setContextMenuPolicy(Qt::NoContextMenu);
mTextBrowser->move(-1, -1);
mTextBrowser->resize(mTextDocument->idealWidth() + 2, height() + 2);
mTextBrowser->show();
update();
}
That stuff is working. Instead of tweaking the QFrame I set my own style.
Only problem is : when entered the newly created TextBrowser never gets deleted.
I guess would need some kind of isActive() flag for the QTextBrowser in order to choose wether I can delete it or not in the leaveEvent.
Thanks man.
Re: QTextEdit drag and drop
Can someone offer advice on how to disable drag and drop in a QTextEdit? I
would like to handle it manually.
Re: QTextEdit drag and drop
Quote:
Originally Posted by
bunjee
Only problem is : when entered the newly created TextBrowser never gets deleted.
Why should it get deleted? Create it when you create the widget and leave it there, regardless of entering or leaving the area. Just use QTextBrowser instead of whatever you used to use there.
Quote:
Originally Posted by
bunjee
Can someone offer advice on how to disable drag and drop in a QTextEdit? I
would like to handle it manually.
Looks like the only thing you want is copy & paste (+drag and drop which is really copy&paste too). Why don't you forget about using a text edit and implement copy & paste functionality for a completely custom widget?