zoukankan      html  css  js  c++  java
  • Q_PROPERTY()自定义类属性

    Q_PROPERTY()--自定义类属性

    #ifndef ICONEDITOR_H
    #define ICONEDITOR_H
    
    #include <QColor>
    #include <QImage>
    #include <QWidget>
    
    class IconEditor : public QWidget
    {
        Q_OBJECT
        Q_PROPERTY(QColor penColor READ penColor WRITE setPenColor)
        Q_PROPERTY(QImage iconImage READ iconImage WRITE setIconImage)
        Q_PROPERTY(int zoomFactor READ zoomFactor WRITE setZoomFactor)
    
    public:
        IconEditor(QWidget *parent = 0);
    
        void setPenColor(const QColor &newColor);
        QColor penColor() const { return curColor; }
        void setZoomFactor(int newZoom);
        int zoomFactor() const { return zoom; }
        void setIconImage(const QImage &newImage);
        QImage iconImage() const { return image; }
        QSize sizeHint() const;

    }

    The IconEditor class uses the Q_PROPERTY() macro to declare three custom properties: penColor, iconImage, and zoomFactor. Each property has a data type, a "read" function, and an optional "write" function. For example, the penColor property is of type QColor and can be read and written using the penColor() and setPenColor() functions.

    When we make use of the widget in Qt Designer, custom properties appear in Qt Designer's property editor below the properties inherited from QWidget. Properties may be of any type supported by QVariant. The Q_OBJECT macro is necessary for classes that define properties.

     

    THE END!

    2012年12月30日

  • 相关阅读:
    opencv c++编译
    报bug
    ssh的server安装和安装指定版本的软件的方法
    caffe修改需要的东西 6:40
    caffe修改需要的东西
    leveldb学习:DBimpl
    AndroidStudio加快Gradle速度的方法-android study之旅(103)
    hdu2222--Keywords Search+AC自己主动机模板
    ListView setOnItemClickListener无效原因分析
    Linux打包命令
  • 原文地址:https://www.cnblogs.com/xingchen/p/2839589.html
Copyright © 2011-2022 走看看