[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,
Katelyn
EDIT: moved to Qt Quick forum, Gerolf
8 replies
Have a look here [doc.qt.nokia.com]
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
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. (@)
What is a .pro file and how does it relate to what I am trying to accomplish?
I was assuming you were using qmake. What build system are you using?
Also, would it be possible to create the scroll bar in C++ to accomplish the same thing I am trying to do in QML?
It would certainly be possible, but I don’t know of any existing implementation. You’d have to write it yourself.
You must log in to post a reply. Not a member yet? Register here!

