PDA

View Full Version : Flickering mouse pointer



guiQt
31st August 2010, 16:51
An extremely simple text editor accepts external file drop changing its title:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setAcceptDrops(true);
}

void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
event->accept();
}

void MainWindow::dragMoveEvent(QDragMoveEvent *event)
{
event->accept();
}

void MainWindow::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasFormat("text/uri-list")) {
QList<QUrl> urls = event->mimeData()->urls();
if (urls.isEmpty())
return;
QString fileName = urls.first().toLocalFile();
if (fileName.isEmpty())
return;
setWindowTitle(tr("%1 - %2").arg(fileName).arg(tr("Drag File")));
}
}
MainWindow has just one widget, textEdit, defined by:

MyTextEdit::MyTextEdit(QWidget *parent)
: QTextEdit(parent)
{
setAcceptDrops(true);
}

void MyTextEdit::dragEnterEvent(QDragEnterEvent *e)
{
if (e->source()) {
if (e->source() == viewport()) {
e->accept();
}
}
}
textEdit accepts only "self" drops, so inserted text can then be moved or copied.
What is the reason of the pointer flickering? How can i remove it?
Thanks.

guiQt
2nd September 2010, 08:50
Bump :confused:

guiQt
7th September 2010, 08:42
Looking for an answer :(

guiQt
11th September 2010, 13:50
Rebump :confused:

Lykurg
11th September 2010, 16:16
I can't see any problem in your code, so can you please provide a minimal compilable example reproducing your problem.

guiQt
12th September 2010, 09:37
droptest example
Problem shows up when you try to move/copy any entered word by dragging/Ctrl+dragging.

Lykurg
12th September 2010, 10:22
Can't reproduce it here on Mac. Where did you see it, Linux (which) or Windows or both?

guiQt
12th September 2010, 10:46
Ubuntu 10.04. Not tested on Windows.

Zlatomir
12th September 2010, 11:37
I have tested on kubuntu 10.4 and there is no "flicker", and can test on ubuntu, but a little bit later

LE:tested on ubuntu 10.4 and didn't flicker.

guiQt
12th September 2010, 13:59
Well, I'm pleased with the correctness of the code, but astonished with the configuration of my system.
Can't think about anything correlated...

tbscope
12th September 2010, 14:34
Try playing with performance settings.

- Update your graphics driver
- Try disabling some desktop effects

guiQt
12th September 2010, 16:23
Tried playing with some Compiz effects, following tbscope's hint.
However I think it's not a performance matter.
The problem seems to be correlated to MyTextEdit widget itself. To prove that, I added a second QTextEdit to MainWindow: flicker shows up only when dragging over MyTextEdit.
P.S. Short video included

Lykurg
12th September 2010, 16:37
Ok, on my console I get
Qt: Internal error: WH0A, unexpected condition reached? Not sure what goes wrong here.

Lykurg
12th September 2010, 16:50
Ehm, I found it: you have forgot to forward the drag to the base class:
void MyTextEdit::dragEnterEvent(QDragEnterEvent *e)
{
if (e->source()) {
if (e->source() == viewport()) {
e->accept();
}
}
QTextEdit::dragEnterEvent(e);
}Also use the Q_OBJECT macro in your own text edit class.

guiQt
13th September 2010, 14:26
The solution proposed by Lykurg removes the flicker, but the drag is not forwarded to the MainWindow when text editor accepts external file drop.
So the code that meets initial requests is:

void MyTextEdit::dragEnterEvent(QDragEnterEvent *e)
{
if (e->source()) {
if (e->source() == viewport()) {
e->accept();
QTextEdit::dragEnterEvent(e);
return;
}
}
e->ignore();
}

wysota
13th September 2010, 15:35
Hmm.... You mean you don't want the text editor to accept any drags apart the ones that originated in itself? Some strange text editor :)

guiQt
13th September 2010, 16:56
:D It's a pure theoretical (and trivial, obviously) case (described above in detail).
The final goal is to develop a lot more complex custom widget (MyTextEdit class with extended QTextEdit functionalities) that besides accepting normal drag and drop originated in itself, it sends external drops to its parent.
This way it's reusable: each application using MyTextEdit class is allowed to manage external drops in its own way.

wysota
13th September 2010, 17:54
I would still want to be able to drop some text snippet into the text editor without having to implement that in the parent/subclass of the editor... Especially if that was part of the original behaviour of the text editor.

guiQt
13th September 2010, 18:11
I would still want to be able to drop some text snippet into the text editor without having to implement that in the parent/subclass of the editor...
Perhaps you'll use YourTextEdit class ;)

wysota
13th September 2010, 18:20
Perhaps I would simply block only those events I explicitly don't want instead of blocking everything which is not what I am interested in at the moment.