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. How to export QGraphicsScene to QImage with HiDPI

How to export QGraphicsScene to QImage with HiDPI

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 403 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.
  • dporobicD Offline
    dporobicD Offline
    dporobic
    wrote on last edited by
    #1

    I have following function that exports my QGraphicsScene to a QImage:

    QImage MyGraphicsScene::image()
    {
    	auto scaleFactor = mDevicePixelRatioScaler->scaleFactor(); // Get the current scale factor in the example it was 2 for 200% scaling
    	QImage image(sceneRect().size().toSize() * scaleFactor, QImage::Format_ARGB32_Premultiplied);
    	image.fill(Qt::white);
    
    	QPainter painter(&image);
    	painter.setRenderHint(QPainter::Antialiasing);
    	render(&painter);
            image.setDevicePixelRatio(scaleFactor);
    
    	return image;
    }
    

    It works fine without HiDPI but with HiDPI enabled, like here set to 200% the exported image looses quality and it looks like this:

    alt text

    The original image looks like this:

    alt text

    Without the scale factor multiplying there the exported images would be small and look like there was no scaling at all so in order to get the size right I have to upscale it but as you can see, I lose quality.

    Does anyone know how to do it right?

    https://github.com/ksnip/ksnip

    1 Reply Last reply
    0
    • dporobicD Offline
      dporobicD Offline
      dporobic
      wrote on last edited by
      #2

      Ok, it looks like the fix was as simple as setting this before creating the QApplication

      QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      

      https://github.com/ksnip/ksnip

      1 Reply Last reply
      2

      • Login

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