[Solved] Scroll bar visible when scrolling
-
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,
KatelynEDIT: moved to Qt Quick forum, Gerolf
-
Have a look "here":http://doc.qt.nokia.com/4.7/qml-integration.html
-
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.7Rectangle {
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 -
[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.