我需要一些帮助。有一个大项目(使用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
}
答案 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);
}