Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Strange behavior while using QGraphicsWidget with QGraphicsDropShadowEffect
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Strange behavior while using QGraphicsWidget with QGraphicsDropShadowEffect

Scheduled Pinned Locked Moved General and Desktop
3 Posts 1 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    remmos
    wrote on last edited by
    #1

    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?)

    1 Reply Last reply
    0
    • R Offline
      R Offline
      remmos
      wrote on last edited by
      #2

      I edited the "Basic-Graphics-Layouts" example to add a QGraphicsDropShadowEffect and it's working perfekt ...

      Is there anything I must note while using QGraphicsWidget with QGraphicsLinearLayout ?

      (Anything I have to reimplement etc. ?)

      1 Reply Last reply
      0
      • R Offline
        R Offline
        remmos
        wrote on last edited by
        #3

        I got it =)

        I forgot setting the "container" (which holds the layout) QGraphicsWidget's geometry ...

        SOLVED

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved