Namespaces
Variants
Actions

How to use QScrollBar in Qt

Jump to: navigation, search
Article Metadata

Article
Created: mind_freak (10 Mar 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

Scroll bar is a control that enables the user to access parts of a document that is larger than the widget used to display it. It provides a visual indication of the user's current position within the document and the amount of the document that is visible. Scroll bars are usually equipped with other controls that enable more accurate navigation. Qt displays scroll bars in a way that is appropriate for each platform.[1]

Scroll1viral.JPG

Various Function

  • To set the orientation of scroll Bar,by default it is horizontal.
QScrollBar *scroll=new QScrollBar();
scroll->setOrientation(Qt::Horizontal/Qt::Vertical);

ScrollBar.JPG

  • To resize the scroll Bar.
scroll->resize(60,40);

Scrollresize.JPG

  • This property holds the page step.
scroll->setPageStep(200);

Scrollsteping.JPG

  • To set the minimum/maximum range of scrollbar.
scroll->setMinimum(0);
scroll->setMaximum(100);

For more details visit: http://doc.trolltech.com/3.3/qscrollbar.html

Source Code

#include <QtGui>
#include <QApplication>
#include<QScrollBar>
#include<QWidget>
#include<QVBoxLayout>
#include<QProgressBar>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *window=new QWidget();
QVBoxLayout *layout =new QVBoxLayout();
QScrollBar *scroll=new QScrollBar();
scroll->setOrientation(Qt::Vertical);
scroll->setMinimum(0);
scroll->setMaximum(100);
scroll->setTracking(0);
scroll->resize(60,40);
scroll->setPageStep(200);
QProgressBar *bar=new QProgressBar();
bar->setMinimum(0);
bar->setMaximum(100);
bar->setTextVisible(1);
layout->addWidget(scroll);
layout->addWidget(bar);
QObject::connect(scroll,SIGNAL(valueChanged(int)),bar,SLOT(setValue(int)));
window->setLayout(layout);
window->show();
return a.exec();
}


Screenshot

For more details visit: http://doc.trolltech.com/3.3/qscrollbar.html

Scrollsteping.JPG

This page was last modified on 11 October 2012, at 04:17.
174 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved