2013-12-12 104 views
0

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

问题功能

+0

在我看来,你想要继承'QProxyStyle'而不是'QStyle'。 – thuga

+0

@thuga好了,当我用'QProxyStyle'替换'QStyle'时,会出现更多的错误,比如'base class undefined',它不能识别'ComplexControl'参数 – DanilGholtsman

+0

'base class undefined'通常意味着你在某处有循环依赖。 – thuga

回答

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); 
} 
+0

以及由于某种原因在我的情况下不工作: – DanilGholtsman