2013-12-12 106 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