How to use QScrollBar in Qt
Article Metadata
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]
Various Function
- To set the orientation of scroll Bar,by default it is horizontal.
QScrollBar *scroll=new QScrollBar(); scroll->setOrientation(Qt::Horizontal/Qt::Vertical);
- To resize the scroll Bar.
scroll->resize(60,40);
- This property holds the page step.
scroll->setPageStep(200);
- 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


(no comments yet)