Qt Forum

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

    Unsolved Scaling a BorderImage source before repeating

    QML and Qt Quick
    borderimage qml scaling
    2
    4
    1130
    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.
    • Phrogz
      Phrogz last edited by Phrogz

      I want to use a border image (two, even) for a progress bar that looks like this:
      Bar made of chevrons

      The bar can be arbitrary width. As it gets longer, the number of chevrons (arrow thingies) in the middle should repeat. No problem, we have horizontalTileMode:BorderImage.Round on our side.

      The bar can be arbitrary height. As it gets taller, the height of the chevrons should scale up. No problem, we set the border.top:0; border.bottom:0; verticalTileMode:BorderImage.Stretch and voila, it stretches.

      However...the aspect ratio of the chevrons should not change. They should always be 45 degree angles. The combination of the above two tile modes makes for too-tall or too-short chevrons if the height of the bar is not exactly the same as the height of the original image source.

      squished chevrons
      stretched chevrons

      What I really want to do is scale the source for the border image based on the height of the bar, and then use that post-scaled image as a border image. Is there any way to do this? Can I somehow create an Image, stretch that, and then use it as an image source for the BorderImage?

      1 Reply Last reply Reply Quote 0
      • J
        Jagh last edited by

        You can subclass QQuickImageProvider to source appropriately scaled images... However, this must be done on C++ side.

        Phrogz 1 Reply Last reply Reply Quote 0
        • Phrogz
          Phrogz @Jagh last edited by

          @Jagh said in Scaling a BorderImage source before repeating:

          You can subclass QQuickImageProvider to source appropriately scaled images... However, this must be done on C++ side.

          Thanks for this. I'd hoped to keep C++ out of this, but this smells doable. What would the usage of this look like in QML for the BorderImage source?

          1 Reply Last reply Reply Quote 0
          • J
            Jagh last edited by

            In C++ you register your image provider by providing a new resource prefix (say you chose "myimage") then in QML it will look like this:

            source: "myimage://myborderImage"
            

            Read Qt doc about QQuickImageProvider class, there is an example of how to use it

            1 Reply Last reply Reply Quote 2
            • First post
              Last post