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>
{
Q_OBJECT
Q_PROPERTY(QColor colorBg READ colorBg WRITE setColorBg
)
public:
QColor colorBg
(){ return _colorBg;
} void setColorBg
(QColor value
){ _colorBg
= value; update
();
}
private:
int _paintWidth;
int _paintHeight;
};
#endif // QAXELPANEL_H
#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
To copy to clipboard, switch view to plain text mode
This is the widget cpp file:
#include "axelpanel.h"
#include <QPainter>
AxelPanel
::AxelPanel(QWidget *parent
){
}
{
Q_UNUSED(event);
painter.
setRenderHint(QPainter::Antialiasing,
true);
painter.setBrush(_colorBg);
painter.drawRect(0,0,width(),height());
}
#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());
}
To copy to clipboard, switch view to plain text mode
Any idea?
Prisco
Bookmarks