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. With Respect To ScrollBar To Rectangle
Forum Updated to NodeBB v4.3 + New Features

With Respect To ScrollBar To Rectangle

Scheduled Pinned Locked Moved QML and Qt Quick
27 Posts 2 Posters 9.5k 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.
  • Pradeep KumarP Pradeep Kumar

    Hello Guys.

    i have a rectangle, how to make rectangle width, height increase with respect to text ins side rectangle, as text increases, rectangle has to increase, and how to add scrollbar to rectangle as soon as text increases. please help me out.

    p3c0P Offline
    p3c0P Offline
    p3c0
    Moderators
    wrote on last edited by
    #2

    @Pradeep-Kumar.M

    i have a rectangle, how to make rectangle width, height increase with respect to text ins side rectangle, as text increases, rectangle has to increase

    You can just simply bind the pointSize or pixelSize of Text to that of Rectangle's width and height with some multiplier.

    width: txtItm.font.pointSize * 10
    height: txtItm.font.pointSize * 5
    

    how to add scrollbar to rectangle as soon as text increases.

    Rectangle doesn't have a built-in scrollbar. You will need to create one yourself.
    But I'm wondering what would you do by adding a Scrollbar to it. Rectangle doesn't scroll. You need something like Flickable where in it would make sense. Example here.

    Also have a look at TextArea, it automatically adds Scrollbar when required.

    157

    Pradeep KumarP 2 Replies Last reply
    1
    • p3c0P p3c0

      @Pradeep-Kumar.M

      i have a rectangle, how to make rectangle width, height increase with respect to text ins side rectangle, as text increases, rectangle has to increase

      You can just simply bind the pointSize or pixelSize of Text to that of Rectangle's width and height with some multiplier.

      width: txtItm.font.pointSize * 10
      height: txtItm.font.pointSize * 5
      

      how to add scrollbar to rectangle as soon as text increases.

      Rectangle doesn't have a built-in scrollbar. You will need to create one yourself.
      But I'm wondering what would you do by adding a Scrollbar to it. Rectangle doesn't scroll. You need something like Flickable where in it would make sense. Example here.

      Also have a look at TextArea, it automatically adds Scrollbar when required.

      Pradeep KumarP Offline
      Pradeep KumarP Offline
      Pradeep Kumar
      wrote on last edited by
      #3

      @p3c0

      thank you, because i want to have scrollbar to my rectangle as soon as text increases and i didnt make use modaldialog,or messagedialog. i made use of rectangle as messagedialog, i will try it.

      Pradeep Kumar
      Qt,QML Developer

      1 Reply Last reply
      0
      • p3c0P p3c0

        @Pradeep-Kumar.M

        i have a rectangle, how to make rectangle width, height increase with respect to text ins side rectangle, as text increases, rectangle has to increase

        You can just simply bind the pointSize or pixelSize of Text to that of Rectangle's width and height with some multiplier.

        width: txtItm.font.pointSize * 10
        height: txtItm.font.pointSize * 5
        

        how to add scrollbar to rectangle as soon as text increases.

        Rectangle doesn't have a built-in scrollbar. You will need to create one yourself.
        But I'm wondering what would you do by adding a Scrollbar to it. Rectangle doesn't scroll. You need something like Flickable where in it would make sense. Example here.

        Also have a look at TextArea, it automatically adds Scrollbar when required.

        Pradeep KumarP Offline
        Pradeep KumarP Offline
        Pradeep Kumar
        wrote on last edited by
        #4

        @p3c0

        and one more i have posted regarding listview, key up pressed and key down pressed

        Pradeep Kumar
        Qt,QML Developer

        Pradeep KumarP 1 Reply Last reply
        0
        • Pradeep KumarP Pradeep Kumar

          @p3c0

          and one more i have posted regarding listview, key up pressed and key down pressed

          Pradeep KumarP Offline
          Pradeep KumarP Offline
          Pradeep Kumar
          wrote on last edited by p3c0
          #5

          @Pradeep-Kumar.M

          and one more thing i want to the difference between contentWidth, contentHeight, contentX, contentY.

          i have a sample code, please look into it.

          import QtQuick 2.4
          import QtQuick.Window 2.2
          
          Window {
              visible: true
              width: 300
              height: 300
              id:win
              Flickable {
                  id: flick
                  width: 80; height: 80
                  contentWidth: image.width
                  contentHeight: image.height
                  contentX: image.x
                  contentY: image.y
          //        contentY: 100
          
                  Image {
                      id: image;
                      width: 50
                      height: 50
                      x: 50
                      y: 100
                      source: "qrc:/new/prefix1/logo.png"
                  }
              }
          }
          

          Pradeep Kumar
          Qt,QML Developer

          p3c0P 1 Reply Last reply
          0
          • Pradeep KumarP Pradeep Kumar

            @Pradeep-Kumar.M

            and one more thing i want to the difference between contentWidth, contentHeight, contentX, contentY.

            i have a sample code, please look into it.

            import QtQuick 2.4
            import QtQuick.Window 2.2
            
            Window {
                visible: true
                width: 300
                height: 300
                id:win
                Flickable {
                    id: flick
                    width: 80; height: 80
                    contentWidth: image.width
                    contentHeight: image.height
                    contentX: image.x
                    contentY: image.y
            //        contentY: 100
            
                    Image {
                        id: image;
                        width: 50
                        height: 50
                        x: 50
                        y: 100
                        source: "qrc:/new/prefix1/logo.png"
                    }
                }
            }
            
            p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #6

            @Pradeep-Kumar.M x and y are for positions while width and height are for dimensions.

            157

            Pradeep KumarP 1 Reply Last reply
            1
            • p3c0P p3c0

              @Pradeep-Kumar.M x and y are for positions while width and height are for dimensions.

              Pradeep KumarP Offline
              Pradeep KumarP Offline
              Pradeep Kumar
              wrote on last edited by
              #7

              @p3c0
              import QtQuick 2.4
              import QtQuick.Window 2.2

              Window {
              id: win
              visible: true
              width: 700
              height: 500
              Rectangle
              {
              id: rect
              width: t1.font.pixelSize * 50
              height: t1.font.pixelSize * 10
              color: "pink"
              Text {
              id: t1
              text: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaajjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjaaaaaaaaaaa"
              }
              }
              }

              as text size increases rectangle has to increase simultaneously , but in this case, its not increasing.

              Pradeep Kumar
              Qt,QML Developer

              Pradeep KumarP 1 Reply Last reply
              0
              • Pradeep KumarP Pradeep Kumar

                @p3c0
                import QtQuick 2.4
                import QtQuick.Window 2.2

                Window {
                id: win
                visible: true
                width: 700
                height: 500
                Rectangle
                {
                id: rect
                width: t1.font.pixelSize * 50
                height: t1.font.pixelSize * 10
                color: "pink"
                Text {
                id: t1
                text: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaajjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjaaaaaaaaaaa"
                }
                }
                }

                as text size increases rectangle has to increase simultaneously , but in this case, its not increasing.

                Pradeep KumarP Offline
                Pradeep KumarP Offline
                Pradeep Kumar
                wrote on last edited by
                #8

                @p3c0

                and one more thing it has to increase dynamically, with respect to text, please help.

                Pradeep Kumar
                Qt,QML Developer

                p3c0P 1 Reply Last reply
                0
                • Pradeep KumarP Pradeep Kumar

                  @p3c0

                  and one more thing it has to increase dynamically, with respect to text, please help.

                  p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #9

                  @Pradeep-Kumar.M hmm you meant length not size. Well in that case you will need get text length and bind it with some multiplier.
                  Its better to use a TextArea here. Isn't it ?

                  157

                  Pradeep KumarP 1 Reply Last reply
                  1
                  • p3c0P p3c0

                    @Pradeep-Kumar.M hmm you meant length not size. Well in that case you will need get text length and bind it with some multiplier.
                    Its better to use a TextArea here. Isn't it ?

                    Pradeep KumarP Offline
                    Pradeep KumarP Offline
                    Pradeep Kumar
                    wrote on last edited by
                    #10

                    @p3c0

                    because data is coming from c++ class thats y, inserting it to rectangle directly . if so how to find text length, do we have length method for text, i didnt find it.

                    Pradeep Kumar
                    Qt,QML Developer

                    p3c0P Pradeep KumarP 2 Replies Last reply
                    0
                    • Pradeep KumarP Pradeep Kumar

                      @p3c0

                      because data is coming from c++ class thats y, inserting it to rectangle directly . if so how to find text length, do we have length method for text, i didnt find it.

                      p3c0P Offline
                      p3c0P Offline
                      p3c0
                      Moderators
                      wrote on last edited by
                      #11

                      @Pradeep-Kumar.M Yes. Use length.

                      157

                      1 Reply Last reply
                      1
                      • Pradeep KumarP Pradeep Kumar

                        @p3c0

                        because data is coming from c++ class thats y, inserting it to rectangle directly . if so how to find text length, do we have length method for text, i didnt find it.

                        Pradeep KumarP Offline
                        Pradeep KumarP Offline
                        Pradeep Kumar
                        wrote on last edited by
                        #12

                        @p3c0

                        thank u for example of scrollbar to rectangle, it worked, one issue in it is ,
                        when i drag down, scrollbar moving upwards, i dont want in that fashion, drag should be with respect to scrollbar, not opposite, please help me.

                        Pradeep Kumar
                        Qt,QML Developer

                        p3c0P 1 Reply Last reply
                        0
                        • Pradeep KumarP Pradeep Kumar

                          @p3c0

                          thank u for example of scrollbar to rectangle, it worked, one issue in it is ,
                          when i drag down, scrollbar moving upwards, i dont want in that fashion, drag should be with respect to scrollbar, not opposite, please help me.

                          p3c0P Offline
                          p3c0P Offline
                          p3c0
                          Moderators
                          wrote on last edited by
                          #13

                          @Pradeep-Kumar.M Must be some problem in your code. Try doing same as done in that example.

                          157

                          Pradeep KumarP 1 Reply Last reply
                          0
                          • p3c0P p3c0

                            @Pradeep-Kumar.M Must be some problem in your code. Try doing same as done in that example.

                            Pradeep KumarP Offline
                            Pradeep KumarP Offline
                            Pradeep Kumar
                            wrote on last edited by
                            #14

                            @p3c0

                            same thing i did it, will you please try, i want the scrollbar to have dragged with respect to mouse simulateonusly, not in opposite fashion, i tried,

                            Pradeep Kumar
                            Qt,QML Developer

                            p3c0P 1 Reply Last reply
                            0
                            • Pradeep KumarP Pradeep Kumar

                              @p3c0

                              same thing i did it, will you please try, i want the scrollbar to have dragged with respect to mouse simulateonusly, not in opposite fashion, i tried,

                              p3c0P Offline
                              p3c0P Offline
                              p3c0
                              Moderators
                              wrote on last edited by
                              #15

                              @Pradeep-Kumar.M Can you explain it w.r.t to that example ? That example works fine as expected.

                              157

                              Pradeep KumarP 1 Reply Last reply
                              1
                              • p3c0P p3c0

                                @Pradeep-Kumar.M Can you explain it w.r.t to that example ? That example works fine as expected.

                                Pradeep KumarP Offline
                                Pradeep KumarP Offline
                                Pradeep Kumar
                                wrote on last edited by
                                #16

                                @p3c0

                                code is working fine, but the thing is scrollbar has to move w.r.t to mouse, when i want to scroll, for example in this forum if u want to scroll up, u will move your mouse up, w.r.t to scrollbar, but in the example case moving mouse upwards, scrolling takes place downwards, i mean to say opposite direction.

                                Pradeep Kumar
                                Qt,QML Developer

                                p3c0P 1 Reply Last reply
                                0
                                • Pradeep KumarP Pradeep Kumar

                                  @p3c0

                                  code is working fine, but the thing is scrollbar has to move w.r.t to mouse, when i want to scroll, for example in this forum if u want to scroll up, u will move your mouse up, w.r.t to scrollbar, but in the example case moving mouse upwards, scrolling takes place downwards, i mean to say opposite direction.

                                  p3c0P Offline
                                  p3c0P Offline
                                  p3c0
                                  Moderators
                                  wrote on last edited by
                                  #17

                                  @Pradeep-Kumar.M Nope. If you scroll down the scrollbar moves down and ofcourse the image will go up and v.v. That's the intended behaviour.

                                  157

                                  Pradeep KumarP 2 Replies Last reply
                                  0
                                  • p3c0P p3c0

                                    @Pradeep-Kumar.M Nope. If you scroll down the scrollbar moves down and ofcourse the image will go up and v.v. That's the intended behaviour.

                                    Pradeep KumarP Offline
                                    Pradeep KumarP Offline
                                    Pradeep Kumar
                                    wrote on last edited by
                                    #18

                                    @p3c0

                                    hm k kk

                                    Pradeep Kumar
                                    Qt,QML Developer

                                    1 Reply Last reply
                                    0
                                    • p3c0P p3c0

                                      @Pradeep-Kumar.M Nope. If you scroll down the scrollbar moves down and ofcourse the image will go up and v.v. That's the intended behaviour.

                                      Pradeep KumarP Offline
                                      Pradeep KumarP Offline
                                      Pradeep Kumar
                                      wrote on last edited by
                                      #19

                                      @p3c0

                                      and one more if we have implementation that works with keys press,
                                      will it work for mouse area on clicked?.

                                      Pradeep Kumar
                                      Qt,QML Developer

                                      p3c0P 1 Reply Last reply
                                      0
                                      • Pradeep KumarP Pradeep Kumar

                                        @p3c0

                                        and one more if we have implementation that works with keys press,
                                        will it work for mouse area on clicked?.

                                        p3c0P Offline
                                        p3c0P Offline
                                        p3c0
                                        Moderators
                                        wrote on last edited by
                                        #20

                                        @Pradeep-Kumar.M Yes should work. Create a function and call that function when required.

                                        157

                                        Pradeep KumarP 1 Reply Last reply
                                        0
                                        • p3c0P p3c0

                                          @Pradeep-Kumar.M Yes should work. Create a function and call that function when required.

                                          Pradeep KumarP Offline
                                          Pradeep KumarP Offline
                                          Pradeep Kumar
                                          wrote on last edited by
                                          #21

                                          @p3c0

                                          you mean to say create function form ex: function sample()
                                          {
                                          // implementation
                                          }

                                          mouse area{
                                          anchors.fill: id
                                          onclicked
                                          {
                                          sample()
                                          }
                                          }

                                          Pradeep Kumar
                                          Qt,QML Developer

                                          p3c0P 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