Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Drawing with units like mm instead of pixels

Drawing with units like mm instead of pixels

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 5.6k 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.
  • H Offline
    H Offline
    h3nk3
    wrote on last edited by
    #1

    Hi,

    We'd like to do all our UI stuff in physical units rather than pixels. For this I implemented one of the solutions referred to by this bug report:

    http://bugreports.qt.nokia.com/browse/QTBUG-11655

    So if I want to use mm instead of pixels I simply write:

    @
    Image {
    width: 45mm
    height: 45
    mm
    source: "gfx/random.svg"
    }
    @

    And the mm is a property defined from C++ like this:

    @
    rootContext->setContextProperty( "mm", viewer.physicalDpiX()/25.4 );
    @

    This works just fine. But the problem occurs when I try to use a BorderImage. The borders are read only and when using this technique it tries to write the result of the multiplication to a read only value. See this example:

    @
    BorderImage {
    source: "gfx/random_border_image.svg"
    width: 22mm
    height: 22
    mm
    border: { left: 3mm; top: 2mm; right: 3.5mm; bottom: 3mm; }
    }
    @

    This gives me the error: "Invalid property assignment: "border" is a read-only property".

    Unfortunately I have not found a way to get around this and still use physical units for our BorderImage's.

    Any ideas?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mario
      wrote on last edited by
      #2

      Don't think you should have ':' after the border, because you're not setting a new Border instance, you only manipulate some properties of the existing border object. Try remove and see what happens.

      @
      border {
      ...
      }
      @

      1 Reply Last reply
      0
      • H Offline
        H Offline
        h3nk3
        wrote on last edited by
        #3

        Thank you Mario, you were absolutely right, it works fine now!

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mario
          wrote on last edited by
          #4

          Cool! Does it work good with physical units?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #5

            I think it's in interesting concept using physical units with border images, but I'm not sure how that is supposed to work.

            The whole nature of a border image is very pixel-centric to begin with. It seems as though you generally want to split a border image on rigidly-fixed positions of the source image. Otherwise you might have some overshooting (or undershooting) boundaries on the image itself depending on the dpi of the display.

            What's your source image like in that sort of scenario?

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply
            0
            • H Offline
              H Offline
              h3nk3
              wrote on last edited by
              #6

              @mario, @mlong: let me get back to you when I have more experience with BorderImages together with svg and physical units. But as long as the BorderImage behaves it should just work using mm instead of pixels. Since we are using svgs things are scaled nicely.

              Right now I'm just using Image instances showing svgs with physical units. And that does indeed work very well. At least on the Symbian platforms. 1*mm gets you 1 mm on the physical devices (tested on an N8 and E7 which have a large resolution difference).

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mlong
                wrote on last edited by
                #7

                Ah! I didn't catch the fact that it's an svg file. In that case I can see how the mm aspect would apply.

                Software Engineer
                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                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