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. QGraphicsView, many non-scaling labels. Best approach
QtWS25 Last Chance

QGraphicsView, many non-scaling labels. Best approach

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 283 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.
  • S Offline
    S Offline
    SandSnip3r
    wrote on last edited by
    #1

    Project:
    I am using a QGraphicsView to display a navmesh/triangulation of large map (250,000 x 500,000). For debugging purposes, I have some toggleable settings to show the labels of triangles, edges, and vertices. These labels really only make sense to be shown once I'm zoomed in at around the 500 x 500 level. Also, these labels should always have the same font size relative to the window (does not change on zoom). There are on the order of millions of labels across the entire map. I have the requirement to be able to read labels at very small scales (smaller than 0.01x0.01).

    What I initially had done:
    Within the QGraphicsView, the entire map is broken up into 2000x2000 regions. These regions were each an instance of a subclassed QGraphicsItem (called RegionGraphicsItem, in my case). Inside the paint() function of the RegionGraphicsItem, I was using the painter to drawText(). I scaled the font size based on the "level of detail" that I was receiving from the QStyleOptionGraphicsItem parameter given to paint(). If the level of detail was below a certain value (too zoomed out), the paint() function would not call drawText().

    This did not work well because when zoomed in very far (maybe around a scale of 10x10) the font scaling calculation led to the text behaving weirdly.

    My second approach:
    I subclassed QGraphicsSimpleTextItem to create a NoScaleLabel class. It simply overrides the paint() function to prevent the scaling of the painter. I add one of these NoScaleLabel objects to the scene for each label (meaning millions of items added to the scene). When I zoom in far enough, I would call setVisible(true) for all labels, and setVisible(false) when zoomed out beyond a certain level.

    This solved my scaling issue; the font looked great at extreme zoom levels. However, performance suffered heavily. Even though all labels are set to not-visible, there is a minute long lag initially when zooming out to view a large portion of the world. There is also noticeable lag when panning the map.

    Question:
    Is there a better option? I need a ton of things available in the scene, but I only need a small subset of them to be visible in the case when I'm zoomed in. Maybe it would make sense to add/remove the items from the scene rather than setting them as visible? But I would only want to add the ones that might be visible, not all million labels for the entire map. Is there something similar to visible that has better performance?

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      Why do you scale the font if the font size does not change? Show only labels in the ROI and move them to the right positions, never scale them?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SandSnip3r
        wrote on last edited by
        #3

        What is ROI? Region of interest?

        If I don't do any work for scaling, then as you zoom in, the font becomes super large. I want the font to always appear the same size, regardless of zoom.

        JoeCFDJ 1 Reply Last reply
        0
        • S SandSnip3r

          What is ROI? Region of interest?

          If I don't do any work for scaling, then as you zoom in, the font becomes super large. I want the font to always appear the same size, regardless of zoom.

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #4

          @SandSnip3r Yes, Region of interest. You do not resize text items at all since font size does not change. You always keep these text items on the top of all items in QGraphicsView if they are visible. Simply move them in the view(their positions change) when ROI changes(zooming). Like they are floating on the view.

          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