上面是效果图,拖动滚动条时,label上的数字会发生变化
代码实现如下:
Dialog.h文件代码
#ifndef DIALOG_H
#define DIALOG_H
#include <QLabel>
#include <QScrollBar>
#include <QDialog>
#define DIALOG_H
#include <QLabel>
#include <QScrollBar>
#include <QDialog>
class Dialog:public QDialog
{
private:
QLabel *label;
QScrollBar *scrollbar;
public:
Dialog(QWidget *parent = 0);
};
{
private:
QLabel *label;
QScrollBar *scrollbar;
public:
Dialog(QWidget *parent = 0);
};
#endif // DIALOG_H
Dialog.cpp文件代码
#include "Dialog.h"
#include <QObject>
#include <QObject>
Dialog::Dialog(QWidget *parent):QDialog(parent)
{
label = new QLabel("0", this);
label->setGeometry( 10, 10, 200, 300);
scrollbar = new QScrollBar(this);
scrollbar->setGeometry(200, 0, 20, 300);
scrollbar->setRange(0, 300);
{
label = new QLabel("0", this);
label->setGeometry( 10, 10, 200, 300);
scrollbar = new QScrollBar(this);
scrollbar->setGeometry(200, 0, 20, 300);
scrollbar->setRange(0, 300);
QObject::connect(scrollbar, SIGNAL(valueChanged(int)),
label, SLOT(setNum(int)));
}
label, SLOT(setNum(int)));
}
main.cpp代码:
#include <QApplication>
#include "Dialog.h"
#include "Dialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Dialog d;
d.show();
{
QApplication app(argc, argv);
Dialog d;
d.show();
return app.exec();
}
}
![]() |
|