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 set ui according to dpi in qt4
QtWS25 Last Chance

How to set ui according to dpi in qt4

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.1k 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.
  • A Offline
    A Offline
    ankursaxena
    wrote on 2 Jun 2014, 04:56 last edited by
    #1

    Hello all,

    I am trying to create an ui which can change its size according to dpi(dots per inch). there may be a method in qt 5 but i want to do it using qt4. So please help me to change ui size according to dpi. How is it possible in qt4 ??

    thank you.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ankursaxena
      wrote on 5 Jun 2014, 06:58 last edited by
      #2

      Here, i can find out physical dpi or logical dpi by using following methods:

      int nY = QApplication::desktop()->physicalDpiY();
      int nX = QApplication::desktop()->physicalDpiX();

      but how can i set size of widget according to above dpi.

      All suggestion are welcomed.
      Thanx in Advance,

      1 Reply Last reply
      0
      • A Offline
        A Offline
        adolby
        wrote on 9 Jun 2014, 18:27 last edited by
        #3

        This Qt Blog article covered the new Qt 5 auto-dpi adjustments, with backports to Qt 4.

        Article: http://blog.qt.digia.com/blog/2013/04/25/retina-display-support-for-mac-os-ios-and-x11/
        Backport: https://codereview.qt-project.org/#change,54636

        If you're able to get the backport patch to work, the desktop manager will report an updated DPI, and Qt will do the adjustment for scalable content automatically. Scalable content includes text size and vector graphics, but not raster graphics by default. Check the article for the details, including using:
        qApp->setAttribute(Qt::AA_UseHighDpiPixmaps);

        If you don't want to go this route, you could possibly scale yourself by using the DPI to make a decision about a resolution to set your app size to. You can do this fixed by creating a set of common DPIs and selecting the one closest to your device value, or by trying to create a scale factor relating DPI to resolution.

        You can set then set the geometry of your widgets based on a percentage of the app you want them to take up. You'd do this by overriding resizeEvents for the widgets you want to change size. The resizeEvent will take the full size it's given, and use percentages of that size to size its children.

        Example: You have a vertical toolbar, a content pane, and a right vertical side bar. The resizeEvent for your containing widget will do:
        @verticalToolBar->setGeometry(0, 0, size.width() * 0.1, size.height());
        contentPane->setGeometry(size.width() * 0.1, 0, size.width() * 0.8, size.height());
        verticalSideBar->setGeometry(size.width() * 0.9, 0, size.width() * 0.1, size.height());@

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ankursaxena
          wrote on 10 Jun 2014, 10:33 last edited by
          #4

          thanx Adolby. I m working on it.

          1 Reply Last reply
          0

          4/4

          10 Jun 2014, 10:33

          • Login

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