Results 1 to 2 of 2

Thread: QCursor with info box

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2006
    Posts
    7
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QCursor with info box

    Hi,

    I'd like to attach a small text based info box to the mouse cursor, when I use a special tool in my application.
    My first idea was to use QLabel without a parent and move the QLabels position to the cursors location.
    To have a more general code, it would be easier to create a custom QCursor handling the text box and replace the QApplications QCursor. Unfortunately, there is a function setOverrideCursor for QGuiApplication only, that will be used already at different locations.
    Is there any way how to set the standard cursors Instance?

    Thanks

  2. #2
    Join Date
    Apr 2006
    Posts
    7
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCursor with info box

    I think I found an elegant solution. The visibility depends on the parents widget - could be the main widget too.


    QCursorLabel::QCursorLabel(QWidget *parent) : QLabel(parent)
    {
    setForegroundRole(QPalette::ToolTipText);
    setBackgroundRole(QPalette::ToolTipBase);
    setPalette(QToolTip:alette());
    setWindowFlags(Qt::ToolTip);
    setText("Set a QLabel Text");
    setVisible(false);
    parent->installEventFilter(this); // so we get the parents widget events
    }


    bool QCursorLabel::eventFilter(QObject *o, QEvent *e)
    {
    if (e->type() == QEvent::HoverMove)
    {
    QHoverEvent *me = dynamic_cast<QHoverEvent *>(e);
    move(parentWidget()->mapToGlobal(me->pos() + QPoint(+10, +10)));
    setVisible(!text().isEmpty());
    }

    if (e->type() == QEvent::Leave) setVisible(false);

    return false;
    }

Similar Threads

  1. Activate QPushButton with QCursor
    By blizniak83 in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2012, 09:01
  2. Comparing QCursor::pos() to QGraphicsItem::pos()
    By mongooseblarg in forum Qt Programming
    Replies: 1
    Last Post: 8th March 2012, 13:30
  3. Replies: 1
    Last Post: 11th April 2009, 22:27
  4. QCursor
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 11th October 2007, 19:57
  5. QCursor::setPos
    By Levon Nikoghosyan in forum Qt Programming
    Replies: 1
    Last Post: 26th December 2006, 08:16

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.