Qt-interest Archive, July 2007
paintEvent() problem + related styling problem
Message 1 in thread
I have two problems and I haven't been able to figure them out myself.
Problem 1: I have subclassed a QFrame as PaintFrame so that I could
re-implement paintEvent() to paint a fading image. I want to use this in
conjunction with an eventfilter I have written (ColorFilter). The filter can
be installed on a QPushButton and linked to an image so that when the user
rolls over a button, the icon in the PaintFrame changes.
The problem is that I don't know how to let the PaintFrame know what to fade
out and what to fade in. The best option would be if I could paint on the
PaintFrame from within my ColorFilter, but I don't know if that's possible
in some way? Otherwise the PaintFrame would have to keep track of all
ColorFilters, the pixmaps they use and the opacity level for those pixmaps.
I'm pretty sure there's an easier solution (besides, I don't even know how I
should implement this in a clean way, because colorfilter.h includes
paintframe.h to be able to link the ColorFilters to the PaintFrame, but if I
wanted to create a QList of ColorFilters in the PaintFrame, I would need to
include colorfilter.h in paintframe.h...)
I have uploaded the code I have right now to this qtnode pastebin:
http://qtnode.net/index.php/pastebin/4250
I'm really hoping that someone can give me constructive critique to help me
fix this in a clean way.
On to problem 2... Related to problem 1, I have promoted one of my QFrames
to a PaintFrame, but the loaded stylesheet that I use to include some
additional styling, does not seem to affect the PaintFrame. I understood
that if I apply a style to a QFrame it should also apply to all subclasses
of QFrame. What is wrong? Actually, the whole frame is not visible anymore,
and it should even be visible without the stylesheet, so I'm really lost
here.
This is the relevant stylesheet code and implementation code:
/////////////// stylesheet (style.qss) ////////////////
QFrame {
background-color: #f7faff;
border-width: 2px;
border-color: #cfdcff;
border-style: solid;
}
QFrame:hover {
background-color: #e6edf8
}
/////////////// implementation ////////////////
void WizardUI::setCustomStyle(bool enable)
{
QString styleSheet;
if (enable)
{
QFile file(":/qss/style.qss");
file.open(QFile::ReadOnly);
styleSheet = QLatin1String(file.readAll());
qApp->setStyleSheet(styleSheet);
} else {
qApp->setStyleSheet("");
}
// additional (default) stylesheet
styleSheet = "QDialog#WinWizard { background: white url(img/altbg.png);
background-repeat: repeat-x; margin: 0px; spacing: 0px; padding: 0px; }";
this->setStyleSheet(styleSheet);
}
Thanks in advance
--
[ signature omitted ]