PDA

View Full Version : QWidget - Q_OBJECT makes the widget disappear



Sir Rogers
25th January 2010, 09:33
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

#ifndef RGCBUTTON_H
#define RGCBUTTON_H

#include <QWidget>

class rgcbutton : public QWidget
{
//Q_OBJECT

public:
rgcbutton(QWidget *parent);
~rgcbutton();

};

#endif // RGCBUTTON_H


rgcbutton.cpp

#include "rgcbutton.h"
#include <QMouseEvent>

rgcbutton::rgcbutton(QWidget *parent) : QWidget(parent)
{
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

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

Sir Rogers
25th January 2010, 10:00
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.

wysota
25th January 2010, 10:38
Your code doesn't make much sense either ;) Use QLabel with QPixmap instead of your class.

Sir Rogers
25th January 2010, 17:33
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.

wysota
25th January 2010, 22:33
But you don't need the stylesheet part. Having a paint event instead is better. So is defining sizeHint().

Sir Rogers
26th January 2010, 00:36
Could you please explain in code what you mean? I'm not following.

wysota
26th January 2010, 00:39
Open up Qt Assistant and type in "paintEvent", then read the page about QWidget that pops up.