Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Cursor Crosshair Lag

Qt Cursor Crosshair Lag

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 971 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yippiyak
    wrote on last edited by VRonin
    #1

    Hello,
    I am attempting to implement a crosshair onto a QtChart, that dynamically tracks the cursor's movement. However, I am experiencing a fair amount of lag between my cursor's position, and the painted crosshair lines. My current code is as follows;

    void SpectrumCoordinateDisplay::paint(QPainter* painter)
    {
        QRectF plotArea = m_chart->plotArea();
        QPointF crossHairPos = m_mousePos;
    
        if (!m_active || !plotArea.contains(crossHairPos))
        {
            return;
        }
    
        painter->setBrush(QColor(255, 255, 0, 255));
        painter->setPen(QColor(255, 255, 0, 255));
    
        const qreal rectSize = 6;
    
        QPointF left(plotArea.left(), crossHairPos.y());
        QPointF right(plotArea.right(), crossHairPos.y());
        QPointF top(crossHairPos.x(), plotArea.top());
        QPointF bottom(crossHairPos.x(), plotArea.bottom());
    
        QRectF crosshairRect(crossHairPos.x() - rectSize, crossHairPos.y() - rectSize, rectSize * 2, rectSize * 2);
        QPointF rectLeft(crosshairRect.left(), crossHairPos.y());
        QPointF rectRight(crosshairRect.right(), crossHairPos.y());
        QPointF rectTop(crossHairPos.x(), crosshairRect.top());
        QPointF rectBottom(crossHairPos.x(), crosshairRect.bottom());
    
        painter->drawLine(left, rectLeft);
        painter->drawLine(right, rectRight);
        painter->drawLine(top, rectTop);
        painter->drawLine(bottom, rectBottom);
        painter->drawLine(crosshairRect.topLeft(), crosshairRect.topRight());
        painter->drawLine(crosshairRect.topLeft(), crosshairRect.bottomLeft());
        painter->drawLine(crosshairRect.bottomRight(), crosshairRect.topRight());
        painter->drawLine(crosshairRect.bottomRight(), crosshairRect.bottomLeft());
    
        QRectF textRect = crosshairRect;
        textRect.moveTop(textRect.top() - textRect.height());
        textRect.setWidth(plotArea.width());
    
        textRect = painter->boundingRect(textRect, Qt::TextWordWrap, m_text);
        textRect.moveBottom(crosshairRect.top());
        textRect.moveLeft(crosshairRect.center().x() + 5);
    
        if (textRect.top() < plotArea.y())
            textRect.moveTop(crosshairRect.bottom());
        if (textRect.right() > plotArea.right())
            textRect.moveRight(crosshairRect.left());
    
        painter->drawText(textRect, Qt::TextWordWrap, m_text);
    }
    

    If anyone has any advice, please let me know.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      What's the base class of SpectrumCoordinateDisplay?
      Did you have a look at the callout example which looks like it does what you are trying to do?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      Y 1 Reply Last reply
      2
      • VRoninV VRonin

        What's the base class of SpectrumCoordinateDisplay?
        Did you have a look at the callout example which looks like it does what you are trying to do?

        Y Offline
        Y Offline
        Yippiyak
        wrote on last edited by
        #3

        @VRonin
        Qt charts.
        The example is not really what I need, as I am basically trying to generate lines that follow the cursor perfectly with no trailing.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved