QWidget - Q_OBJECT makes the widget disappear
Ok hey guys, I have a very very weird bug. If I add the Q_OBJECT line to the class it makes it disappear. I have kept the class very small to show the bug. The class works like a charm when Q_OBJECT isn't present, but I need it to emit signals.
By disappear I mean that it doesn't show the class at all anymore on the UI, on the widget. It still somewhat works, because it creates a new window if I set the parent to NULL, indicating that the class is still somewhat operational.
rgcbutton.h
Code:
#ifndef RGCBUTTON_H
#define RGCBUTTON_H
#include <QWidget>
{
//Q_OBJECT
public:
~rgcbutton();
};
#endif // RGCBUTTON_H
rgcbutton.cpp
Code:
#include "rgcbutton.h"
#include <QMouseEvent>
{
QImage ximg; ximg.
load("skins/default/images/exit_inactive.png");
setStyleSheet("background-image: url(skins/default/images/exit_inactive.png);");
setFixedSize(ximg.size());
}
rgcbutton::~rgcbutton() { }
Implementation (Some random QWidget
Code:
login
::login(QWidget *parent
) : QWidget(parent, Qt
::FramelessWindowHint), ui
(new Ui
::login){
ui
->setupUi
(this); move
(QApplication::desktop()->geometry
().
center() - rect
().
center());
rgcbutton *TT = new rgcbutton(this);
TT->move(20, 20);
}
I'm stuck on this and I don't know what's happening. Your help is very much appreciated. This is the warning I get when I compile without Q_OBJECT. Maybe it helps: rgcbutton.h:0: Warning: No relevant classes found. No output generated.
Regards,
Sir Rogers
Re: QWidget - Q_OBJECT makes the widget disappear
I have no idea why, but adding another widget into the rgcbutton class solves the problem:
QWidget *randomWidget;
randomWidget = new QWidget(this);
This really doesn't make sense.
Re: QWidget - Q_OBJECT makes the widget disappear
Your code doesn't make much sense either ;) Use QLabel with QPixmap instead of your class.
Re: QWidget - Q_OBJECT makes the widget disappear
I narrowed it down to a basic level so it was easier to read. I'm using it to create a button with images. I need the mouseMoveEvent for that.
Re: QWidget - Q_OBJECT makes the widget disappear
But you don't need the stylesheet part. Having a paint event instead is better. So is defining sizeHint().
Re: QWidget - Q_OBJECT makes the widget disappear
Could you please explain in code what you mean? I'm not following.
Re: QWidget - Q_OBJECT makes the widget disappear
Open up Qt Assistant and type in "paintEvent", then read the page about QWidget that pops up.