Qt5项目部署 - 使用QProxyStyle

时间:2013-12-12 08:18:24

标签: c++ qt deployment qt4 qt5

我需要一些帮助。有一个大项目(使用Qt4创建)我尝试使用Qt5运行。如您所知QWindowStyle已在Qt5中删除,但使用了一个函数。我用QProxyStyle替换了它,但它没有帮助。

编译器说QProxyStyle::drawComplexControl Illegal call to non-static member function

它与Qt4一起工作,为什么它在这里不起作用?或者使用QProxyStyle不是个好主意?

下载一些代码

.h文件类声明

class MultiAxesPlot::LegendStyle:public QStyle
{
    Q_OBJECT
public:
    LegendStyle( LegendStyle const &other){}
    LegendStyle(){}
    ~LegendStyle(){}
    virtual void drawComplexControl( ComplexControl control, const QStyleOptionComplex * option, QPainter * painter, const QWidget * widget = 0 ) const;
};

问题功能

void MultiAxesPlot::LegendStyle::drawComplexControl( ComplexControl control, const QStyleOptionComplex * option, QPainter * painter, const QWidget * widget /*= 0 */ ) const
{
    if( option->type == QStyleOption::SO_TitleBar )
    {
        //some stuff
            return;
    }
    QProxyStyle::drawComplexControl( control, option, painter, widget );    
    //QWindowStyle:drawComplexControl( control, option, painter, widget ); how it looked like before

}

1 个答案:

答案 0 :(得分:0)

这对我有用:

//.h
#ifndef MYSTYLE_H
#define MYSTYLE_H

#include <QProxyStyle>

class MyStyle : public QProxyStyle
{
    Q_OBJECT
public:
    explicit MyStyle(QStyle *parent = 0);

protected:
    void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const;

};
#endif // MYSTYLE_H

//.cpp
#include "mystyle.h"
#include <QStyleOption>

MyStyle::MyStyle(QStyle *parent) :
    QProxyStyle(parent)
{
}

void MyStyle::drawComplexControl(QStyle::ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
{
    if(option->type == QStyleOption::SO_TitleBar)
    {
        //do something
        return;
    }
    QProxyStyle::drawComplexControl(control, option, painter, widget);
}
相关问题