0
votes

I need some help again. There is some big project (created using Qt4) which I try to run with using Qt5. As you know QWindowStyle has removed in Qt5 but one function were used it. I replaced it with QProxyStyle but it didn't help.

Compiler says QProxyStyle::drawComplexControl Illegal call to non-static member function

It worked with Qt4 why it doesn't work here? Or use QProxyStyle is not good idea?

Heres some code

.h file class declaration

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;
};

problem function

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
It seems to me like you want to subclass QProxyStyle and not QStyle. - thuga
@thuga well, there are more errors when I replace QStyle with QProxyStyle like base class undefined and it not recognize ComplexControl param - DanilGholtsman
base class undefined usually means that you have circular dependency somewhere. - thuga
@thuga well and what else it could be? I think there are no circular dependency - DanilGholtsman
Don't care if there are more errors, subclass QProxyStyle and then paste the errors you get in that case. Also drop that copy constructor. - peppe

1 Answers

0
votes

This works for me:

//.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);
}