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. How to render text with less height but same width?
Forum Updated to NodeBB v4.3 + New Features

How to render text with less height but same width?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 4 Posters 1.0k Views 3 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.
  • P Offline
    P Offline
    patrickkidd
    wrote on last edited by
    #1

    I am trying to improve on the Tumbler type in QtQuick.Controls by rendering the height of each item a little smaller according to the item's current displacement, just as is done in the iOS date picker. It might also make sense to decrease the padding between items as displacement increases as well.

    0_1559804518259_Screen Shot 2019-06-05 at 11.01.04 PM.png

    Any ideas on how to do that?

    Thanks!

    https://alaskafamilysystems.com/

    raven-worxR 1 Reply Last reply
    0
    • P patrickkidd

      I am trying to improve on the Tumbler type in QtQuick.Controls by rendering the height of each item a little smaller according to the item's current displacement, just as is done in the iOS date picker. It might also make sense to decrease the padding between items as displacement increases as well.

      0_1559804518259_Screen Shot 2019-06-05 at 11.01.04 PM.png

      Any ideas on how to do that?

      Thanks!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @patrickkidd
      you can play around with item transformations

      Item {
          transform: [
             Scale { yScale: 3; ... },
             Rotation { axis { x: 1; y: 0; z: 0 } angle: ... }
         ]
      }
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      P 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @patrickkidd
        you can play around with item transformations

        Item {
            transform: [
               Scale { yScale: 3; ... },
               Rotation { axis { x: 1; y: 0; z: 0 } angle: ... }
           ]
        }
        
        P Offline
        P Offline
        patrickkidd
        wrote on last edited by patrickkidd
        #3

        @raven-worx The following code:

            Component {
                id: delegateComponent
                Label {
                    text: formatText(Tumbler.tumbler.count, modelData)
                    height: Tumbler.tumbler.visibleItemCount * 5
                    opacity: 1.0 - Math.abs(Tumbler.displacement) / (Tumbler.tumbler.visibleItemCount / 2)
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                    font.pixelSize: fontMetrics.font.pixelSize * 1.25// * (1.0 - Math.abs(Tumbler.displacement) / Tumbler.tumbler.visibleItemCount)                                                                     
                    transform: Scale {
                        yScale: (1.0 - Math.abs(Tumbler.displacement) / Tumbler.visibleItemCount)
                    }
                }
            }
        

        gives me this warning on the line with transform: Scale {:

        qrc:/qml/PK/PKDatePicker.qml(39): qrc:/qml/PK/PKDatePicker.qml:39:24: QML Scale: Tumbler: attached properties of Tumbler must be accessed through a delegate item
        qrc:/qml/PK/PKDatePicker.qml(39): qrc:/qml/PK/PKDatePicker.qml:39:24: QML Scale: Tumbler: attached properties of Tumbler must be accessed through a delegate item
        qrc:/qml/PK/PKDatePicker.qml(39): qrc:/qml/PK/PKDatePicker.qml:39:24: QML Scale: Tumbler: attached properties of Tumbler must be accessed through a delegate item
        qrc:/qml/PK/PKDatePicker.qml(39): qrc:/qml/PK/PKDatePicker.qml:39:24: QML Scale: Tumbler: attached properties of Tumbler must be accessed through a delegate item
        qrc:/qml/PK/PKDatePicker.qml(39): qrc:/qml/PK/PKDatePicker.qml:39:24: QML Scale: Tumbler: attached properties of Tumbler must be accessed through a delegate item
        qrc:/qml/PK/PKDatePicker.qml(39): qrc:/qml/PK/PKDatePicker.qml:39:24: QML Scale: Tumbler: attached properties of Tumbler must be accessed through a delegate item
        qrc:/qml/PK/PKDatePicker.qml(39): qrc:/qml/PK/PKDatePicker.qml:39:24: QML Scale: Tumbler: attached properties of Tumbler must be accessed through a delegate item
        qrc:/qml/PK/PKDatePicker.qml(39): qrc:/qml/PK/PKDatePicker.qml:39:24: QML Scale: Tumbler: attached properties of Tumbler must be accessed through a delegate item
        qrc:/qml/PK/PKDatePicker.qml(39): qrc:/qml/PK/PKDatePicker.qml:39:24: QML Scale: Tumbler: attached properties of Tumbler must be accessed through a delegate item
        

        https://alaskafamilysystems.com/

        1 Reply Last reply
        0
        • Shrinidhi UpadhyayaS Offline
          Shrinidhi UpadhyayaS Offline
          Shrinidhi Upadhyaya
          wrote on last edited by Shrinidhi Upadhyaya
          #4

          Hi @patrickkidd ,

          just create a simple property like this inside the Label

          property real scaleVal: Math.abs(Tumbler.displacement) / (control.visibleItemCount / 2)
          

          and then access it like this:-

           transform: Scale {
                      yScale:1.0 - label.scaleVal
                  }
          

          And the font size of the current item and the other items is also different, so according to my needs i had written a simple login like this, you can customize according to your needs:-

          opacity: Math.max(1.0 - Math.abs(Tumbler.displacement) / (control.visibleItemCount / 2), 0.4)
          font.pixelSize: root.fontSize * opacity
          

          And i guess you can also use the opacity mask if you want achieve fading effect which the items at the bottom and top have.

          Sample code:-

           Image {
              id: masking
          
              height: tumblerItem.height
              width: tumblerItem.width
              source: "mask.png"
              visible: false
          }
          
          OpacityMask {
              height: tumblerItem.height
              width: tumblerItem.width
              source: tumblerItem
              maskSource: masking
          }
          

          Sample output:-

          0_1559807185515_326ad7c1-8e5d-4342-b66c-43389ed5f399-image.png

          Shrinidhi Upadhyaya.
          Upvote the answer(s) that helped you to solve the issue.

          P 1 Reply Last reply
          2
          • GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by GrecKo
            #5

            This effect is not just a scaling on the vertical axis.
            My guess is that it should be done with shaders.

            1 Reply Last reply
            0
            • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

              Hi @patrickkidd ,

              just create a simple property like this inside the Label

              property real scaleVal: Math.abs(Tumbler.displacement) / (control.visibleItemCount / 2)
              

              and then access it like this:-

               transform: Scale {
                          yScale:1.0 - label.scaleVal
                      }
              

              And the font size of the current item and the other items is also different, so according to my needs i had written a simple login like this, you can customize according to your needs:-

              opacity: Math.max(1.0 - Math.abs(Tumbler.displacement) / (control.visibleItemCount / 2), 0.4)
              font.pixelSize: root.fontSize * opacity
              

              And i guess you can also use the opacity mask if you want achieve fading effect which the items at the bottom and top have.

              Sample code:-

               Image {
                  id: masking
              
                  height: tumblerItem.height
                  width: tumblerItem.width
                  source: "mask.png"
                  visible: false
              }
              
              OpacityMask {
                  height: tumblerItem.height
                  width: tumblerItem.width
                  source: tumblerItem
                  maskSource: masking
              }
              

              Sample output:-

              0_1559807185515_326ad7c1-8e5d-4342-b66c-43389ed5f399-image.png

              P Offline
              P Offline
              patrickkidd
              wrote on last edited by patrickkidd
              #6

              @Shrinidhi-Upadhyaya this is very cool. It looks to me that apple decreases the space between items as displacement increases. Any thoughts on how to do that?

              @GrecKo What else do you see? I know that at least in iOS 12 there is a scale and transform that occurs as soon as the current item enters into the two horizontal lines. It is very cool, no way to accomplish that without using a clipped child rectangle and second tumbler inside it.

              0_1560107987795_40E819D4-847F-47A2-9A65-89462D32EB04.jpeg

              https://alaskafamilysystems.com/

              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