Prisco
8th June 2016, 11:44
Hi everyone,
I'm using Qt 5.6 and I'm having some issues with custom widgets. I've added a QWidget to a to a .ui file, promoted it to my custom widget (a simple colored panel) but when I run the application i can't see my widget and get this output message:
"QFormBuilder was unable to create a custom widget of the class 'AxelPanel'; defaulting to base class 'QWidget'."
This is the widget header file:
#ifndef QAXELPANEL_H
#define QAXELPANEL_H
#include <QWidget>
class AxelPanel : public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor colorBg READ colorBg WRITE setColorBg)
public:
AxelPanel(QWidget *parent = 0);
void paintEvent(QPaintEvent *e);
QColor colorBg(){ return _colorBg;}
void setColorBg(QColor value){ _colorBg = value; update();}
private:
QColor _colorBg;
int _paintWidth;
int _paintHeight;
};
#endif // QAXELPANEL_H
This is the widget cpp file:
#include "axelpanel.h"
#include <QPainter>
AxelPanel::AxelPanel(QWidget *parent)
: QWidget(parent)
{
_colorBg = QColor(50,50,50);
}
void AxelPanel::paintEvent(QPaintEvent* event)
{
Q_UNUSED(event);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setBrush(_colorBg);
painter.drawRect(0,0,width(),height());
}
Any idea?
Prisco
I'm using Qt 5.6 and I'm having some issues with custom widgets. I've added a QWidget to a to a .ui file, promoted it to my custom widget (a simple colored panel) but when I run the application i can't see my widget and get this output message:
"QFormBuilder was unable to create a custom widget of the class 'AxelPanel'; defaulting to base class 'QWidget'."
This is the widget header file:
#ifndef QAXELPANEL_H
#define QAXELPANEL_H
#include <QWidget>
class AxelPanel : public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor colorBg READ colorBg WRITE setColorBg)
public:
AxelPanel(QWidget *parent = 0);
void paintEvent(QPaintEvent *e);
QColor colorBg(){ return _colorBg;}
void setColorBg(QColor value){ _colorBg = value; update();}
private:
QColor _colorBg;
int _paintWidth;
int _paintHeight;
};
#endif // QAXELPANEL_H
This is the widget cpp file:
#include "axelpanel.h"
#include <QPainter>
AxelPanel::AxelPanel(QWidget *parent)
: QWidget(parent)
{
_colorBg = QColor(50,50,50);
}
void AxelPanel::paintEvent(QPaintEvent* event)
{
Q_UNUSED(event);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setBrush(_colorBg);
painter.drawRect(0,0,width(),height());
}
Any idea?
Prisco