zoukankan      html  css  js  c++  java
  • Qt ScrollArea

    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
    
  • 相关阅读:
    暴力程序之回文子串
    关于取消同步带来问题的样例
    JavaScript之Date
    JavaScript之array
    智破连环阵
    超长数字串
    无向图最短路径
    扫雷
    n!最末尾非0数
    计算程序运行时间
  • 原文地址:https://www.cnblogs.com/johnpher/p/2673441.html
Copyright © 2011-2022 走看看