大家好,又见面了,我是你们的朋友全栈君。
We can show a image with automatic scroll bars with the use of QScrollArea.
This is a simple application with QScrollArea.
#include <QtGui/QApplication>
#include <QLabel>
#include <QScrollArea>
#include "qmlapplicationviewer.h"
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *imageLabel = new QLabel;
QImage image(":/image.jpg");
imageLabel->setPixmap(QPixmap::fromImage(image));
QScrollArea *scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel);
scrollArea->show();
return app.exec();
}
In addation, we can inherit from QScrollArea and then use the class we inherited as a widget which is able to scroll automatically.
Like this:
#ifndef PICWINDOW_H
#define PICWINDOW_H
#include <QScrollArea>
class QLabel;
class QImage;
class PicWindow : public QScrollArea
{
Q_OBJECT
public:
explicit PicWindow(QWidget *parent = 0);
private:
QLabel *imageLabel;
QImage *image;
signals:
public slots:
};
#endif // PICWINDOW_H
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/107084.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...