Qt5项目部署-QProxy样式使用

Qt5 project deployment - QProxyStyle using

本文关键字:样式 -QProxy 部署 项目 项目部 Qt5      更新时间:2023-10-16

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