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. [Solved] Scroll bar visible when scrolling
Forum Updated to NodeBB v4.3 + New Features

[Solved] Scroll bar visible when scrolling

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 2 Posters 5.1k Views 1 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.
  • K Offline
    K Offline
    kbt90
    wrote on last edited by
    #1

    Hello -

    I am looking to create a scroll bar that is visible only when scrolling. I am using flickable and have found several examples of QML code that will do this for me. What I am wondering is how to incorporate it into my C++ code. Is it as simple as just setting the style sheet in my .cpp file for the flickable object?

    If not, how do I embed QML code in C++. I have looked at many different resources, but cannot find an example that fully makes sense to me. I am relatively new to this.

    Thanks for your help,
    Katelyn

    EDIT: moved to Qt Quick forum, Gerolf

    1 Reply Last reply
    0
    • L Offline
      L Offline
      loladiro
      wrote on last edited by
      #2

      Have a look "here":http://doc.qt.nokia.com/4.7/qml-integration.html

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kbt90
        wrote on last edited by
        #3

        Thank you - I found that helpful. I am receiving several errors:

        error: 'QDeclarativeView' was not declared in this scope
        error: 'qmlScroll' was not declared in this scope
        error: expected type-specifier before 'QDeclarativeView'
        error: expected ';' before 'QDeclarativeView'

        QDeclarativeView is a subclass of QWidget, which has been included in the file.

        The following is the portion of c++ code that adds the scroll bar to the ui:

        QVBoxLayout *vLayout = new QVBoxLayout;
        QDeclarativeView *qmlScroll = new QDeclaritiveView;
        qmlScroll->setSource(QUrl::fromLocalFile("ScrollBar.qml"));
        vLayout->addWidget(qmlScroll);

        The following is the qml code for the scroll bar:
        import Qt 4.7

        Rectangle {
        id: container
        color: black;

        property var flickableArea

        Rectangle {
        y: flickableArea.visibleArea.yPosition * container.height
        width: parent.width
        height: flickableArea.visibleArea.heightRatio * container.height
        color: "gray"
        opacity: 0.7
        }

        opacity: flickableArea.moving? .7 : 0;
        opacity: Behavior { NumberAnimation { duration: 400 } }
        }

        I am unsure as to what I am doing incorrectly. Any help would be much appreciated.

        Thanks,
        Katelyn

        1 Reply Last reply
        0
        • L Offline
          L Offline
          loladiro
          wrote on last edited by
          #4

          Do you have:
          @
          #include <QDeclarativeView>
          @
          in you .cpp file and
          @QT += declarative
          CONFIG(debug, debug|release):CONFIG += declarative_debug
          @
          in your .pro file? That might me the problem. And please use Code Wrappers. (@)

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kbt90
            wrote on last edited by
            #5

            What is a .pro file and how does it relate to what I am trying to accomplish?

            Also, would it be possible to create the scroll bar in C++ to accomplish the same thing I am trying to do in QML?

            1 Reply Last reply
            0
            • L Offline
              L Offline
              loladiro
              wrote on last edited by
              #6

              [quote author="kbt90" date="1307722818"]What is a .pro file and how does it relate to what I am trying to accomplish?
              [/quote]
              I was assuming you were using qmake. What build system are you using?

              [quote author="kbt90" date="1307722818"]
              Also, would it be possible to create the scroll bar in C++ to accomplish the same thing I am trying to do in QML?
              [/quote]
              It would certainly be possible, but I don't know of any existing implementation. You'd have to write it yourself.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kbt90
                wrote on last edited by
                #7

                I am building in an arm environment.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  loladiro
                  wrote on last edited by
                  #8

                  Well, make sure you're linking against the QtDeclarative library then (if it's available for arm - I don't know that, otherwise you'll have to rewrite it in plain C++)

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kbt90
                    wrote on last edited by
                    #9

                    okay, thanks for your help!

                    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