PDA

View Full Version : Simple and silly question about QWidget



dima
2nd December 2010, 07:24
I have default application CTest based on QMainWindow.

If I add Qt class dirive from QWidget , do I have to add also UI file for that class ????????????
//Code Not working CTest inherite QWidget


#include "test3.h"
#include <QWidget>
#include "CTest.h"
test3::test3(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);

m_pT = new CTest(ui.centralWidget);
m_pT->setStyleSheet("QWidget { background-color: blue; }");
}

//Code working
#include "test3.h"
#include <QWidget>
test3::test3(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);

QWidget* pT = new QWidget(ui.centralWidget);
pT->setStyleSheet("QWidget { background-color: blue; }");
}

high_flyer
2nd December 2010, 09:47
Just post the code please, its easy to misunderstand your explanation.

wysota
2nd December 2010, 10:10
If you reimplemented the paintEvent for the CTest class then stylesheets won't work, they only work with default widgets as the drawing goes through the style then. Instead of stylesheets you can always use QPalette.

dima
2nd December 2010, 10:14
I didn't reimplemented anything , I just added new class to project that derive QWidget , with no more extra code lines.