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. QToolbar High-resolution (high dpi)
Forum Updated to NodeBB v4.3 + New Features

QToolbar High-resolution (high dpi)

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 853 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.
  • asdfjklA Offline
    asdfjklA Offline
    asdfjkl
    wrote on last edited by
    #1

    I am trying to optimize an application for high - resolution displays. In order to simulate this, I set the DPI setting on Windows 10 higher than normal, so that I have a devicePixelRatio of 2.

    I am loading high resolution SVG images, render them to a QPixmap, and set these as QIcons on the Toolbar. For that I need the iconSize information of the toolbar.

    However the toolbar reports its IconSize way too small, so that there are large borders around the image.

    I guess a picture says more than 1000 words: Left (sharp but borders) is done by rendering to proper size taking toolbar-iconSize info into account, on the right is just creating a QIcon directly from the SVG
    https://postimg.org/image/66me68gzx/

    For the left case (sharp, but borders around the icon) I am creating the Icons like this:

    ImageSize = toolbar.IconSize()
    const qreal PixelRatio = this->devicePixelRatio();
    QSvgRenderer svgRenderer(SvgFile);
    QPixmap img = new QPixmap(ImageSizePixelRatio);
    QPainter Painter;
    img->fill(Qt::transparent);
    Painter.begin(img);
    svgRenderer.render(&Painter);
    Painter.end();
    img->setDevicePixelRatio(PixelRatio);
    toolbar.addIcon(QIcon(img))

    for the right (blurry, but no borders) case I am just doing

    toolbar.addIcon(QIcon(svgFile)

    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