I am trying to create a custom widgetclass which inherits from QWidget. The problem is, that as I add the Q_OBJECT macro to my custom class, the widget doesn't get displayed (no erros). If I remove the macro run qmake und run the project again, the customwidget is shown. I am used to add the Q_Object macro because I want to add signals and slots.
Widget.h:
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
};
#endif // WIDGET_H
Widget.cpp:
#include "Widget.h"
Widget::Widget(QWidget *parent) : QWidget(parent) { }
main.cpp:
#include "Widget.h"
#include <QApplication>
#include <QWidget>
#include <QPoint>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget window_main;
Widget *widget_steps = new Widget(&window_main);
widget_steps->setFixedWidth(100);
widget_steps->setFixedHeight(100);
widget_steps->move(QPoint(0, 0));
widget_steps->setStyleSheet("background-color: red");
window_main.showMaximized();
return a.exec();
}
Without Q_OBJECT macro a red rect is shown on the upper-left corner, if I add the macro, it isn't shown. I am using Qt 5.1 and Windows 7.
I am new to Qt, so please keep your answers simple :)