[SOLVED] Strange behavior while using QGraphicsWidget with QGraphicsDropShadowEffect
-
Hello,
I've a prob with my own QGraphicsWidget subclass and QGraphicsDropShadowEffect ...
My QGraphicsWidget should be something like a "Toolbar" with outer-glow - should be 100% width and 150px height.
So far no problem:
In my MainWindow (QGraphicsView) I've done this:
@
MainWindow::MainWindow(QWidget *parent) :
QGraphicsView(parent),
scene(new QGraphicsScene)
{
this->setScene(scene);
this->setMinimumSize(1024, 768);
this->setStyleSheet("background-color: #151515;");
this->setWindowTitle("Test 1");MenuBar *menuBar = new MenuBar(); menuBar->setParentView(this); scene->addItem(menuBar); this->show();
}
void MainWindow::resizeEvent(QResizeEvent *event) {
this->scene->setSceneRect(QRectF(QPointF(0, 0), event->size()));
QGraphicsView::resizeEvent(event);
}
@And my subclass MenuBar of QGraphicsWidget:
@
MenuBar::MenuBar(QGraphicsWidget *parent) :
QGraphicsWidget(parent)
{
glowEffectTimer = new QTimer();
connect(glowEffectTimer, SIGNAL(timeout()), this, SLOT(updateGlowEffectColor()));
glowEffectTimer->setInterval(500);
glowEffectTimer->start();glowEffect = new QGraphicsDropShadowEffect; glowEffect->setBlurRadius(30); glowEffect->setOffset(0, 2); this->setGraphicsEffect(glowEffect);
}
void MenuBar::setParentView(QGraphicsView *parentView) {
this->parentView = parentView;
}void MenuBar::updateGlowEffectColor() {
glowColor->setHsv((glowColor->hue() < 359 ? (glowColor->hue()+2) : 0), 215, 215, 128);
glowEffect->setColor(*glowColor);
}void MenuBar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QLinearGradient bgGradient(QPointF(0, 0), QPointF(0, 150));
bgGradient.setColorAt(0, QColor((QRgb)0xff3f3f3f));
bgGradient.setColorAt(0.47, QColor((QRgb)0xff282828));
bgGradient.setColorAt(0.48, QColor((QRgb)0xff151515));
bgGradient.setColorAt(1, QColor((QRgb)0xff202020));painter->setBrush(bgGradient); painter->drawRoundedRect(0, -15, parentView->width(), 165, 15, 15);
}
@My problem now is, that the rectangle is not drawn correctly, BUT ONLY if I set the effect !?
(Is there any posibility to get this working with layouts?)