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. ScrollView & QQuickPaintedItem
QtWS25 Last Chance

ScrollView & QQuickPaintedItem

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlscrollviewscrollbarc++
8 Posts 2 Posters 1.7k Views
  • 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.
  • Q Offline
    Q Offline
    Quawetim
    wrote on 7 Nov 2019, 07:00 last edited by Quawetim 11 Jul 2019, 08:33
    #1

    Hello there. I'm trying to use ScrollView with my custom class View derived from QQuickPaintedItem but scroll bars not working.

    Here is some qml code:

    ScrollView {
    	anchors.top: _topBar.bottom
    	anchors.bottom: _footer.top
    	anchors.left: _leftBar.right
    	anchors.right: parent.right
    
    	clip: true
    	wheelEnabled: false
    
    	ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
    	ScrollBar.vertical.policy: ScrollBar.AlwaysOn	
    		
    	View {
    		id: view
    		anchors.fill: parent			
    	}
    }
    

    It works properly with Image but not with my View.
    The problem is i want to draw some data with QPainter in C++ backend and this image can be very wide. So i want to use ScrollBars to navigate. Maybe i should use another classes and techniques?

    UPDATE:
    Thanks to brute force (and Qt Docs) I found a solution. ScrollView wants to know how big the content is (View). Thus you should specify the contentWidth & contentHeight properties (these are the Pane properties, which is the basic element for ScrollView).

    NOTE: the anchors.fill: parent is needed too.

    So the working code is here:

    ScrollView {
    	anchors.top: _topBar.bottom
    	anchors.bottom: _footer.top
    	anchors.left: _leftBar.right
    	anchors.right: parent.right
    
    	clip: true
    	wheelEnabled: false
    
    	ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
    	ScrollBar.vertical.policy: ScrollBar.AlwaysOn	
    
    	contentWidth: 5000
    	contentHeight: 5000
    
    	View {
    		id: view
    		anchors.fill: parent
    	}		
    }
    
    K 1 Reply Last reply 7 Nov 2019, 07:20
    0
    • Q Quawetim
      7 Nov 2019, 07:00

      Hello there. I'm trying to use ScrollView with my custom class View derived from QQuickPaintedItem but scroll bars not working.

      Here is some qml code:

      ScrollView {
      	anchors.top: _topBar.bottom
      	anchors.bottom: _footer.top
      	anchors.left: _leftBar.right
      	anchors.right: parent.right
      
      	clip: true
      	wheelEnabled: false
      
      	ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
      	ScrollBar.vertical.policy: ScrollBar.AlwaysOn	
      		
      	View {
      		id: view
      		anchors.fill: parent			
      	}
      }
      

      It works properly with Image but not with my View.
      The problem is i want to draw some data with QPainter in C++ backend and this image can be very wide. So i want to use ScrollBars to navigate. Maybe i should use another classes and techniques?

      UPDATE:
      Thanks to brute force (and Qt Docs) I found a solution. ScrollView wants to know how big the content is (View). Thus you should specify the contentWidth & contentHeight properties (these are the Pane properties, which is the basic element for ScrollView).

      NOTE: the anchors.fill: parent is needed too.

      So the working code is here:

      ScrollView {
      	anchors.top: _topBar.bottom
      	anchors.bottom: _footer.top
      	anchors.left: _leftBar.right
      	anchors.right: parent.right
      
      	clip: true
      	wheelEnabled: false
      
      	ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
      	ScrollBar.vertical.policy: ScrollBar.AlwaysOn	
      
      	contentWidth: 5000
      	contentHeight: 5000
      
      	View {
      		id: view
      		anchors.fill: parent
      	}		
      }
      
      K Offline
      K Offline
      KroMignon
      wrote on 7 Nov 2019, 07:20 last edited by KroMignon 11 Jul 2019, 07:23
      #2

      @Quawetim Hi, I would suggest you to remove the anchors in View item. This Item have to set himself the width and height it requires, so ScollView can do the job. With ancors.fill: parent width and height are link to ScollView, so no need for scrollbars!

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      Q 1 Reply Last reply 7 Nov 2019, 07:52
      0
      • K KroMignon
        7 Nov 2019, 07:20

        @Quawetim Hi, I would suggest you to remove the anchors in View item. This Item have to set himself the width and height it requires, so ScollView can do the job. With ancors.fill: parent width and height are link to ScollView, so no need for scrollbars!

        Q Offline
        Q Offline
        Quawetim
        wrote on 7 Nov 2019, 07:52 last edited by
        #3

        @KroMignon, without anchors QML/Qt draws nothing at all. Just empty space on the screen, and there are no errors in the output. It seems that QML/Qt wants the width/height of the View or something else, but when i specifying this (in QML), nothing is drawn either.

        K 1 Reply Last reply 7 Nov 2019, 08:58
        0
        • Q Quawetim
          7 Nov 2019, 07:52

          @KroMignon, without anchors QML/Qt draws nothing at all. Just empty space on the screen, and there are no errors in the output. It seems that QML/Qt wants the width/height of the View or something else, but when i specifying this (in QML), nothing is drawn either.

          K Offline
          K Offline
          KroMignon
          wrote on 7 Nov 2019, 08:58 last edited by
          #4

          @Quawetim I mean this:

          ScrollView {
          	anchors.top: _topBar.bottom
          	anchors.bottom: _footer.top
          	anchors.left: _leftBar.right
          	anchors.right: parent.right
          
          	clip: true
          	wheelEnabled: false
          
          	ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
          	ScrollBar.vertical.policy: ScrollBar.AlwaysOn	
          
          	View {
          		id: view
          		//anchors.fill: parent
          	        width: 5000
          	        height: 5000
          	}		
          }
          

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          Q 1 Reply Last reply 7 Nov 2019, 09:08
          0
          • K KroMignon
            7 Nov 2019, 08:58

            @Quawetim I mean this:

            ScrollView {
            	anchors.top: _topBar.bottom
            	anchors.bottom: _footer.top
            	anchors.left: _leftBar.right
            	anchors.right: parent.right
            
            	clip: true
            	wheelEnabled: false
            
            	ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
            	ScrollBar.vertical.policy: ScrollBar.AlwaysOn	
            
            	View {
            		id: view
            		//anchors.fill: parent
            	        width: 5000
            	        height: 5000
            	}		
            }
            
            Q Offline
            Q Offline
            Quawetim
            wrote on 7 Nov 2019, 09:08 last edited by
            #5

            @KroMignon, it does not works. Also empty space. I added solution to the first post.

            K 1 Reply Last reply 7 Nov 2019, 09:21
            0
            • Q Quawetim
              7 Nov 2019, 09:08

              @KroMignon, it does not works. Also empty space. I added solution to the first post.

              K Offline
              K Offline
              KroMignon
              wrote on 7 Nov 2019, 09:21 last edited by
              #6

              @Quawetim Sorry I made a mistake, should be implicitHeightandimplicitWidth`, like this small project (Qt 5.12.5)

              import QtQuick 2.12
              import QtQuick.Window 2.12
              import QtQuick.Controls 2.12
              
              Window {
                 visible: true
                 width: 640
                 height: 480
                 title: qsTr("Hello World")
              
                 ScrollView {
                     anchors.fill: parent
              
                     clip: true
                     wheelEnabled: false
              
                     ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
                     ScrollBar.vertical.policy: ScrollBar.AlwaysOn
                     Rectangle {
                         implicitWidth: 5000
                         implicitHeight: 5000
                         gradient: Gradient {
                             GradientStop { position: 0.0; color: "lightsteelblue" }
                             GradientStop { position: 1.0; color: "blue" }
                         }
                     }
                 }
              }
              ``

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              Q 1 Reply Last reply 8 Nov 2019, 04:42
              0
              • K KroMignon
                7 Nov 2019, 09:21

                @Quawetim Sorry I made a mistake, should be implicitHeightandimplicitWidth`, like this small project (Qt 5.12.5)

                import QtQuick 2.12
                import QtQuick.Window 2.12
                import QtQuick.Controls 2.12
                
                Window {
                   visible: true
                   width: 640
                   height: 480
                   title: qsTr("Hello World")
                
                   ScrollView {
                       anchors.fill: parent
                
                       clip: true
                       wheelEnabled: false
                
                       ScrollBar.horizontal.policy: ScrollBar.AlwaysOn
                       ScrollBar.vertical.policy: ScrollBar.AlwaysOn
                       Rectangle {
                           implicitWidth: 5000
                           implicitHeight: 5000
                           gradient: Gradient {
                               GradientStop { position: 0.0; color: "lightsteelblue" }
                               GradientStop { position: 1.0; color: "blue" }
                           }
                       }
                   }
                }
                ``
                Q Offline
                Q Offline
                Quawetim
                wrote on 8 Nov 2019, 04:42 last edited by
                #7

                @KroMignon, yep, it works. But is there any difference between implicitWidth/Height in View/Rectangle and contentWidth/Height in ScrollView? Which practice is better?

                K 1 Reply Last reply 8 Nov 2019, 07:05
                0
                • Q Quawetim
                  8 Nov 2019, 04:42

                  @KroMignon, yep, it works. But is there any difference between implicitWidth/Height in View/Rectangle and contentWidth/Height in ScrollView? Which practice is better?

                  K Offline
                  K Offline
                  KroMignon
                  wrote on 8 Nov 2019, 07:05 last edited by
                  #8

                  @Quawetim I don't know which is better. For my comprehension, it is easier to use implicitHeight/implicitWidth of the item to be scrolled.

                  For example, when the item is a ListView, implicitHeight is automatically updated when an element from the ListView is changed/added/removed.
                  Your View item only have to set implicitHeight/implicitWidth and dynamically the ListView will adapt the scollbars limits/positions

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  1 Reply Last reply
                  0

                  3/8

                  7 Nov 2019, 07:52

                  5 unread
                  • Login

                  • Login or register to search.
                  3 out of 8
                  • First post
                    3/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved