Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Drawing with units like mm instead of pixels

    QML and Qt Quick
    3
    7
    5009
    Loading More Posts
    • 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
      h3nk3 last edited by

      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 Reply Quote 0
      • M
        mario last edited by

        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 Reply Quote 0
        • H
          h3nk3 last edited by

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

          1 Reply Last reply Reply Quote 0
          • M
            mario last edited by

            Cool! Does it work good with physical units?

            1 Reply Last reply Reply Quote 0
            • M
              mlong last edited by

              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 Reply Quote 0
              • H
                h3nk3 last edited by

                @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 Reply Quote 0
                • M
                  mlong last edited by

                  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 Reply Quote 0
                  • First post
                    Last post