我再次需要一些帮助。有一个大项目(使用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
}
这对我有效:
//.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);
}