June 9, 2011

kbt90 kbt90
Lab Rat
37 posts

[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

June 10, 2011

loladiro loladiro
Lab Rat
596 posts

Have a look here [doc.qt.nokia.com]

June 10, 2011

kbt90 kbt90
Lab Rat
37 posts

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

June 10, 2011

loladiro loladiro
Lab Rat
596 posts

Do you have:

  1. #include <QDeclarativeView>

in you .cpp file and
  1. QT += declarative
  2. CONFIG(debug, debug|release):CONFIG += declarative_debug

in your .pro file? That might me the problem. And please use Code Wrappers. (@)

June 10, 2011

kbt90 kbt90
Lab Rat
37 posts

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?

June 10, 2011

loladiro loladiro
Lab Rat
596 posts

kbt90 wrote:
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?

kbt90 wrote:

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.

June 10, 2011

kbt90 kbt90
Lab Rat
37 posts

I am building in an arm environment.

June 10, 2011

loladiro loladiro
Lab Rat
596 posts

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++)

June 10, 2011

kbt90 kbt90
Lab Rat
37 posts

okay, thanks for your help!

 
  ‹‹ [Solved]Highlight and PathView don’t work, do not understand why !      How do you access properties of a QML component in C++? ››

You must log in to post a reply. Not a member yet? Register here!