Results 1 to 6 of 6

Thread: mouseTracking on QLabels with rich-text?

  1. #1
    Join Date
    Jan 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default mouseTracking on QLabels with rich-text?

    Hey-ho!

    I've a little problem, I'm sure it's just me not knowing the Qt-context, so hopefully that wont be difficult.

    I'd like to use a Picture as mouse Pointer. So I switched my MainWindow to enable mouseTracking via the Designer, added a QLabel, loaded my Pixmap... every thing working so far. Now i wanted to place a QLabel on my Mainwindow. And of course it should also accept the picture as mouse:

    Qt Code:
    1. //...
    2. QLabel * textLabel = new QLabel(widget);
    3. textLabel->setMouseTracking(true);
    4. textLabel->setCursor(QCursor(Qt::BlankCursor));
    5. //...
    To copy to clipboard, switch view to plain text mode 

    The after a while I add some text to the label:

    Qt Code:
    1. //...
    2. project1->labels.at(1)->setText("Foo"); //dont bother with the vector, just the place our label from above went ;)
    3. //...
    To copy to clipboard, switch view to plain text mode 
    Still everything is fine, I see the text where it should be and I can move the mouse over it.

    But if I try the same with html inside the String, all of a sudden the mouseTracking wont work any more:
    Qt Code:
    1. //...
    2. project1->labels.at(1)->setText("<b>Foo</b>");
    3. //...
    To copy to clipboard, switch view to plain text mode 

    When I try to move the mouse over the Label now, the mouse-picture gets caught at the edges of the Label. The mouse is moving on invisibly, emerging on the other side of the Label, and then the pictures changes its location to the new mouse location.

    Everything I changed was the added html inside the String. So i guess, my Labeltext changed from plain to richtext. But whats the matter with the mouseTracking not working anymore?

    Ohh... and heres the picture-following-the mouse algorithm, just in case...
    Qt Code:
    1. void MainWindow::mouseMoveEvent(QMouseEvent * pEvent)
    2. {
    3. ui->fingerLabel->move(pEvent->x() - 50, pEvent->y() + 1);
    4. }
    To copy to clipboard, switch view to plain text mode 

    I would realy appreciate some hints.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: mouseTracking on QLabels with rich-text?

    Ohh... and heres the picture-following-the mouse algorithm, just in case...
    Maybe I don't understand, but if you want your own image as a mouse cursor, why don't you just set it, instead of the empty cursor you are setting?
    You don't need to follow the mouse your self then.
    This is probably why your cursor disappears when you go over the label.
    I don't know why it disappears only for html text, maybe it uses a default cursor for non html label when none is set.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: mouseTracking on QLabels with rich-text?

    Hmm... it's 3:30 in the morning and I'm back again. Oo

    Well, setting the Cursor to my image worked pretty well (thanks a lot, had no idea that I can make a cursor from my own pixmaps!).

    But actually I need the mouseTracking for some other feautures (e.g. gesture recognition). I surely could use some tricks to make it work without, but thats surly not how nature intended it.

    So anybody an idea what could be wrong with my html-labels?

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: mouseTracking on QLabels with rich-text?

    So anybody an idea what could be wrong with my html-labels?
    What is the problem you are having?
    In your original post I thought it was using a custom mouse cursor.
    But since now you know how to do that, what is the current problem you have?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jan 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: mouseTracking on QLabels with rich-text?

    When I try to move the mouse over the Label now, the mouse-picture gets caught at the edges of the Label. The mouse is moving on invisibly, emerging on the other side of the Label, and then the pictures changes its location to the new mouse location.
    To make it short:
    QLabel with normal text: setMouseTracking(true) works.
    QLabel with richtext: setMouseTracking(true) dosn't work.

    Whereas doesn't work means: compiles fine without warnings, but doesn't track the mouse while running.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: mouseTracking on QLabels with rich-text?

    Since the label probably tracks the mouse itself, it eats up the events you would like to be getting. Installing an event filter and tracking the events there might be a solution although I consider it a strange thing that you wish to track gestures when a mouse button is not pressed. You might be interpreting random mouse movements as gestures. It might not be what people expect.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Rich text in QGraphicsTextItem
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2008, 20:08
  2. Rich Text in QTableWidgetItem
    By joshuajcarson in forum Qt Programming
    Replies: 9
    Last Post: 2nd September 2008, 15:49
  3. Rich text with QPainter?
    By sarefo in forum Qt Programming
    Replies: 3
    Last Post: 7th April 2008, 14:40
  4. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45
  5. Painting Rich Text
    By xanthine in forum Qt Programming
    Replies: 7
    Last Post: 15th April 2006, 23:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.