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. now they want a pattern...
Forum Updated to NodeBB v4.3 + New Features

now they want a pattern...

Scheduled Pinned Locked Moved Solved QML and Qt Quick
16 Posts 3 Posters 2.0k Views 2 Watching
  • 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.
  • oria66O Offline
    oria66O Offline
    oria66
    wrote on last edited by oria66
    #2

    @mzimmers Hi. I faced a similar problem in the past. The ways I found:

    1. Load an image.
    2. Use Canvas to draw black lines over a red rectangle.
    3. Use QQuickPaintedItem to do the same as item 2 but in C++ (You can use a Qt::BrushStyle).

    I hope it helps.

    The truth is out there

    1 Reply Last reply
    2
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #3

      You could also draw a bunch of rectangles vertically inside a rectangle. Then rotate them. Set clipping to true on outside rectangle.

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      1
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #4

        Wiggle timer is optional. I just did it for the lols.

        import QtQuick 2.15
        import QtQuick.Window 2.15
        
        Window {
            width: 480
            height: 480
            visible: true
            title: qsTr("pattern")
        
            Timer {
                id: wiggletimer
        
                interval: 1000
                running: true
                repeat: false
        
                property real wiggle: 0.0
        
                onTriggered: {
                    interval = (Math.random() + 0.5) * 5000;
                    wiggle = Math.random() * 0.5
        
                    start()
                }
            }
        
            Rectangle {
                id: masterrect
        
                anchors.centerIn: parent
        
                width: 400
                height: 400
        
                border.width: 1
        
                Item {
                    anchors.fill: parent
                    anchors.margins: 1
        
                    clip: true
        
                    Rectangle {
                        width: parent.width * 1.5
                        height: parent.height * 1.5
        
                        anchors.centerIn: parent
        
                        rotation: 45 + wiggletimer.wiggle
        
                        Repeater {
                            id: rmodel
        
                            model: 20
        
                            Rectangle {
                                property real size: parent.width / rmodel.count
        
                                height: parent.height * 1.5
                                width: size * 0.2
        
                                x: size * 0.5 + size * index - width/2
        
                                color: "black"
                            }
                        }
                    }
                }
            }
        }
        

        C++ is a perfectly valid school of magic.

        1 Reply Last reply
        4
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #5

          I don't know how performant it will be. It might be dog slow.

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          0
          • mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #6

            Lots of good suggestions...I went with what was easiest (for me), which was using an image:

            Rectangle {
            ...
                Image {
                    id: highlight
                    source: resourceHelper.imageSourcePrefix + "images/hatch.png"
                    visible: (cellText === "S1")
                    height: parent.height
                    width: parent.width
                    fillMode: Image.Pad
                }
            

            Produces this:
            highlight.PNG

            Thanks for all the good ideas.

            Oh, fcarney: the wiggle performance wasn't terrible, but it was quite subtle -- it took me a while to realize that anything was even changing.

            mz

            fcarneyF oria66O 2 Replies Last reply
            2
            • mzimmersM mzimmers

              Lots of good suggestions...I went with what was easiest (for me), which was using an image:

              Rectangle {
              ...
                  Image {
                      id: highlight
                      source: resourceHelper.imageSourcePrefix + "images/hatch.png"
                      visible: (cellText === "S1")
                      height: parent.height
                      width: parent.width
                      fillMode: Image.Pad
                  }
              

              Produces this:
              highlight.PNG

              Thanks for all the good ideas.

              Oh, fcarney: the wiggle performance wasn't terrible, but it was quite subtle -- it took me a while to realize that anything was even changing.

              mz

              fcarneyF Offline
              fcarneyF Offline
              fcarney
              wrote on last edited by
              #7

              @mzimmers That looks really nice.

              C++ is a perfectly valid school of magic.

              1 Reply Last reply
              0
              • mzimmersM mzimmers

                Lots of good suggestions...I went with what was easiest (for me), which was using an image:

                Rectangle {
                ...
                    Image {
                        id: highlight
                        source: resourceHelper.imageSourcePrefix + "images/hatch.png"
                        visible: (cellText === "S1")
                        height: parent.height
                        width: parent.width
                        fillMode: Image.Pad
                    }
                

                Produces this:
                highlight.PNG

                Thanks for all the good ideas.

                Oh, fcarney: the wiggle performance wasn't terrible, but it was quite subtle -- it took me a while to realize that anything was even changing.

                mz

                oria66O Offline
                oria66O Offline
                oria66
                wrote on last edited by
                #8

                @mzimmers Hi. I like the UI style. If all your items have round corners, maybe the cross-lined rectangle should have too, in order to maintain consistency.

                The truth is out there

                mzimmersM 1 Reply Last reply
                2
                • oria66O oria66

                  @mzimmers Hi. I like the UI style. If all your items have round corners, maybe the cross-lined rectangle should have too, in order to maintain consistency.

                  mzimmersM Offline
                  mzimmersM Offline
                  mzimmers
                  wrote on last edited by mzimmers
                  #9

                  @oria66 oh man...I completely overlooked that. Good catch...thanks!

                  EDIT:

                  But...how does one radius an Image? I wonder if a different fill mode is the answer...?

                  oria66O 1 Reply Last reply
                  0
                  • mzimmersM mzimmers

                    @oria66 oh man...I completely overlooked that. Good catch...thanks!

                    EDIT:

                    But...how does one radius an Image? I wonder if a different fill mode is the answer...?

                    oria66O Offline
                    oria66O Offline
                    oria66
                    wrote on last edited by oria66
                    #10

                    @mzimmers Also. All your rectangles have separations (5 px?) and S3 and S2 don't have one. In the name of consistency too, lol. By the way, really love the color selection. Is it for an industry application? Kind of HMI?

                    The truth is out there

                    mzimmersM 1 Reply Last reply
                    0
                    • oria66O oria66

                      @mzimmers Also. All your rectangles have separations (5 px?) and S3 and S2 don't have one. In the name of consistency too, lol. By the way, really love the color selection. Is it for an industry application? Kind of HMI?

                      mzimmersM Offline
                      mzimmersM Offline
                      mzimmers
                      wrote on last edited by
                      #11

                      @oria66 said in now they want a pattern...:

                      @mzimmers Also. All your rectangles have separations (5 px?) and S3 and S2 don't have one. ​In the name of consistency too, lol.

                      Yep...that's actually a faithful representation of the rack. Bottles S2 and S3 share a long slot because there just wasn't room for a separator.

                      By the way, really love the color selection. Is for an industry application? Kind of HMI?

                      It's a medical research application. The customer supplied the colors. They're fine for the UI, but our attempt to use them for QR barcode symbols was not successful, so we're looking at alternatives.

                      oria66O 1 Reply Last reply
                      0
                      • mzimmersM mzimmers

                        @oria66 said in now they want a pattern...:

                        @mzimmers Also. All your rectangles have separations (5 px?) and S3 and S2 don't have one. ​In the name of consistency too, lol.

                        Yep...that's actually a faithful representation of the rack. Bottles S2 and S3 share a long slot because there just wasn't room for a separator.

                        By the way, really love the color selection. Is for an industry application? Kind of HMI?

                        It's a medical research application. The customer supplied the colors. They're fine for the UI, but our attempt to use them for QR barcode symbols was not successful, so we're looking at alternatives.

                        oria66O Offline
                        oria66O Offline
                        oria66
                        wrote on last edited by
                        #12

                        @mzimmers mmm, I see. I don't think a fill mode property works for that kind of use. Maybe two options here: 1. Edit the image in an external editor (the easy way I believe). 2. Maybe, some crop function following a shape. I know this can be achieved with QPainter and QImage on the C++ side, but on the QML side, I don't know.

                        The truth is out there

                        1 Reply Last reply
                        0
                        • mzimmersM Offline
                          mzimmersM Offline
                          mzimmers
                          wrote on last edited by
                          #13

                          I don't think editing the image is the right approach, as the image is applied to bottles of multiple sizes (though I suppose I could create multiple files, one for each bottle size). Also, I'd have to do the radiusing by hand, and I don't have any editing tools for that.

                          oria66O 1 Reply Last reply
                          0
                          • mzimmersM mzimmers

                            I don't think editing the image is the right approach, as the image is applied to bottles of multiple sizes (though I suppose I could create multiple files, one for each bottle size). Also, I'd have to do the radiusing by hand, and I don't have any editing tools for that.

                            oria66O Offline
                            oria66O Offline
                            oria66
                            wrote on last edited by
                            #14

                            @mzimmers Maybe this can help you.

                            https://stackoverflow.com/questions/42432456/circular-image-in-qt-qml/42432691

                            The truth is out there

                            mzimmersM 1 Reply Last reply
                            1
                            • oria66O oria66

                              @mzimmers Maybe this can help you.

                              https://stackoverflow.com/questions/42432456/circular-image-in-qt-qml/42432691

                              mzimmersM Offline
                              mzimmersM Offline
                              mzimmers
                              wrote on last edited by
                              #15

                              @oria66 oh, that is a thing of beauty:

                                Rectangle {
                                  id: bottle
                                  property int radiusValue: 5 * bottleScaleFactor
                                  radius: radiusValue
                              
                                  Image {
                                      id: highlight
                                      source: resourceHelper.imageSourcePrefix + "images/hatch.png"
                                      visible: (cellText.charAt(0) == "S")
                                      height: parent.height
                                      width: height
                                      fillMode: Image.Pad
                                      layer.enabled: true
                                      layer.effect: OpacityMask {
                                          maskSource: opacityMask
                                      }
                                  }
                                  Rectangle {
                                      id: opacityMask
                                      height: parent.height
                                      width: height
                                      visible: false
                                      radius: parent.radiusValue
                                  }
                              

                              highlight.PNG
                              (I changed it so the entire group is highlighted.)

                              Thank you SO much for finding that!

                              oria66O 1 Reply Last reply
                              1
                              • mzimmersM mzimmers

                                @oria66 oh, that is a thing of beauty:

                                  Rectangle {
                                    id: bottle
                                    property int radiusValue: 5 * bottleScaleFactor
                                    radius: radiusValue
                                
                                    Image {
                                        id: highlight
                                        source: resourceHelper.imageSourcePrefix + "images/hatch.png"
                                        visible: (cellText.charAt(0) == "S")
                                        height: parent.height
                                        width: height
                                        fillMode: Image.Pad
                                        layer.enabled: true
                                        layer.effect: OpacityMask {
                                            maskSource: opacityMask
                                        }
                                    }
                                    Rectangle {
                                        id: opacityMask
                                        height: parent.height
                                        width: height
                                        visible: false
                                        radius: parent.radiusValue
                                    }
                                

                                highlight.PNG
                                (I changed it so the entire group is highlighted.)

                                Thank you SO much for finding that!

                                oria66O Offline
                                oria66O Offline
                                oria66
                                wrote on last edited by
                                #16

                                @mzimmers glad to help.

                                The truth is out there

                                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