hi
In the following program the stylesheet works for Widget class only when i comment the Q_OBJECT macro.
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui>
{
Q_OBJECT//if this line is commented the setStyleSheet works.
public:
};
{
Q_OBJECT
public:
private:
Widget *widget;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui>
class Widget:public QWidget
{
Q_OBJECT//if this line is commented the setStyleSheet works.
public:
Widget(QWidget *parent=0);
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
private:
Widget *widget;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp file
#include "mainwindow.h"
{
}
MainWindow
::MainWindow(QWidget *parent
){
widget = new Widget();
widget->setStyleSheet("background-color:red");
setCentralWidget(widget);
}
#include "mainwindow.h"
Widget::Widget(QWidget *parent) :QWidget(parent)
{
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
widget = new Widget();
widget->setStyleSheet("background-color:red");
setCentralWidget(widget);
}
To copy to clipboard, switch view to plain text mode
main.cpp file
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
how to set the stylesheet of the Widget Class.
Bookmarks