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
    
  • 相关阅读:
    等价表达式
    读入字符串
    n以内质数占的比例
    图论——最小生成树_prim
    搜索
    图论——最小生成树
    线段树模板
    WC总结
    三练斜率优化
    斜率优化技巧——换个角度思考
  • 原文地址:https://www.cnblogs.com/johnpher/p/2673441.html
Copyright © 2011-2022 走看看