B
B
BogBel2015-04-19 23:20:42
Qt
BogBel, 2015-04-19 23:20:42

Creating a widget inherited from QPaintDevice?

The crux of the matter is this.
I read M. Schlee Qt section with graphics. It says that to draw a QPainter object, you need space to draw it, for example, a widget inherited from QPaintDevice.
But QPaintDevice is an abstract class with a single virtual method virtual QPaintEngine * paintEngine() const = 0. I'm struggling with overloading this function in my widget.
//widget.h code
#ifndef WIDGET_H
#define WIDGET_H
#include
#include
#include
namespace Ui {
class Widget;
}
class Widget :public QWidget, public QPaintDevice
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
QPaintEngine::paintDevice() const;
private:
Ui::Widget *ui;
};
#endif // WIDGET_H //widget.cpp
code
#include "widget.h"
#include "ui_widget.h"
#include
#include
#include
#include
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui( new Ui::Widget)
{
ui->setupUi(this);
QPainter obj1(this);
obj1.setRenderHint(QPainter::Antialiasing,true);
obj1.setBrush(QBrush(Qt::red));
obj1.setPen(QPen(Qt::blue));
obj1.drawRect(QRect(10,10,110,70));
}
Widget::~Widget()
{
delete ui;
}
Widget::QPaintEngine::paintDevice() const
{
}
//main.cpp
#include "widget.h"
#include
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
//erorrs
The compiler complains about an attempt to create a virtual class object.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tugo, 2015-04-19
@BogBel

QWidget itself already inherits from QPaintDevice.
Something like this rghost.ru/6pydHZDQZ

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question