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 and adding scrollbars to app window

ScrollView and adding scrollbars to app window

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 982 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.
  • T Offline
    T Offline
    teemo10
    wrote on last edited by
    #1

    I am trying to add scrollbars to my app's main window using the following code:

    @import QtQuick 2.0
    import QtQuick.Controls 1.0

    ScrollView {
    Rectangle {
    id: mainWindow
    width: 360; height: 360
    gradient: Gradient {
    GradientStop { position: 0.0; color: "red"}
    GradientStop { position: 1.0; color: "blue" }
    }

        Text {
            anchors.centerIn: parent
            text: "Hello World"
        }
    }
    

    }@

    I'm trying to:

    Give the window a gradient background, regardless of the window size.

    Be able to specify a virtual size of for my window(e.g. 360x360). So that the scrollbars show up if the window size becomes smaller than the virtual size, otherwise they disappear.

    The code above satisfies the second part, but not the first. So the scrollbars show up and disappear correctly. However the gradient only shows up for part of the screen, resizing it beyond the virtual size shows white. Using anchors.fill: parent breaks things completely.

    Is using ScrollView the right way to go? If so what am I missing?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on last edited by
      #2

      This is straight forward actually. ScrollView itself is not visible. All you have to do is to make the gradient rectangle the background, parent the scrollView inside it and create an invisible content item in the scroll Area:

      @
      import QtQuick 2.0
      import QtQuick.Controls 1.0

      Rectangle {
      id: mainWindow
      gradient: Gradient {
      GradientStop { position: 0.0; color: "red"}
      GradientStop { position: 1.0; color: "blue" }
      }
      Text {
      anchors.centerIn: parent
      text: "Hello World"
      }
      ScrollView {
      anchors.fill: parent
      Item {
      width: 360
      height: 360
      }
      }
      }
      @

      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