PDA

View Full Version : Assigning new QStyle



seux
29th August 2011, 13:26
Hello everyone,
I want to create my own Style, so I created a class which inherits QStyle. This class does till now nothing



//MyStyleClass.h
class MyStyle : public QStyle
{
Q_OBJECT
public:
MyStyle();

void polish(QPalette &palette);
}


//MyStyleClass.cpp
MyStyle::MyStyle()
{
}

void MyStyle::polish(QPalette &palette)
{
}

My test programm is just a dialog box with a button assigned. But how can I assign the new Style to my programm?
I tried it out in the main() function via:

QApplication::setStyle(new MyStyle);
but I just get an error from the compiler which says:
cannot allocate an object of abstract type 'MyStyle'
because the following virtual functions are pure within 'MyStyle':
virtual void QStyle::drawPrimitive(QStyle::PrimitiveElements, const QStyleOption*, QPainter*, const Qwidget*) const;
and a lot more functions

Rachol
29th August 2011, 13:30
That's quite an obvious error. Your implementation of QStyle is incomplete. There is bunch of pure virtual functions in QStyle that you must implement. Try subclassing already existing, fully implemented style, it will be easier. QMotifStyle or whatever other style you like.