Bad QGraphicsView rendering by combining QGraphicsProxyWidget and QGraphicsDropShadowEffect

  • I have stumbled upon a problem of bad rendering the QGraphicsView when a drop shadow effect is used on its containing widget combined with the fact that its scene contains custom QGraphicsItem with embedded widget. Here is an example especially prepared to demonstrate this issue (it is not the code of my application, but a minimal one to show what happens). Please note, that commenting of either or both of the designated lines removes this undesired effect. How do you think - is this a bug in Qt, or something is missing in the code to make it work properly? Any ideas will be much appreciated.


    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QMainWindow>
    #include <QApplication>
    #include <QDesktopWidget>
    #include <QVBoxLayout>
    #include <QWidget>
    #include <QGraphicsDropShadowEffect>
    #include <QGraphicsProxyWidget>
    #include <QGraphicsRectItem>
    #include <QGraphicsView>
    #include <QLineEdit>
    #include <QBrush>
    class MyRect : public QGraphicsRectItem
    public: MyRect();
    QLineEdit *w;
    QGraphicsProxyWidget *g;
    class Form : public QWidget
        explicit Form(QWidget *parent = 0);
        void setScene(QGraphicsScene *scene);
    private: QGraphicsView *view;
    class MainWindow : public QMainWindow
    public: explicit MainWindow(QWidget *parent = 0);
    #endif // MAINWINDOW_H


    #include "MainWindow.h"
    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
        QGraphicsScene *scene = new QGraphicsScene(this);
        QGraphicsView *view = new QGraphicsView(this);
        QRect g = QApplication::desktop()->screenGeometry();
        int h = g.height(), w = g.width();
        setGeometry((w-800)/2, (h-600)/2, 800, 600);
        Form *form = new Form(this);
        form->setGeometry(0, 0, 198, 763);
        for (int n = 0; n < 7; n++)
            MyRect *r = new MyRect();
            r->setPos(20, 70*n + 50);
        setFlags(ItemIsSelectable | ItemIsMovable);
        setRect(0, 0, 90, 60);
        w = new QLineEdit();
        w->setGeometry(0, 0, 90, 20);
        g = new QGraphicsProxyWidget(this);
        g->setWidget(w); // Comment this: problem is gone, but no Line Edit
    Form::Form(QWidget *parent) : QWidget(parent)
        view = new QGraphicsView(this);
        view->setAlignment(Qt::AlignLeft | Qt::AlignTop);
        QVBoxLayout *layout = new QVBoxLayout(this);
        QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect();
        effect->setColor(QColor(150, 150, 150));
        setGraphicsEffect(effect); // Comment this: problem is gone, but no shadow
    void Form::setScene(QGraphicsScene *scene)

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    From your description, it looks like QTBUG-44355, isn't it ?

  • Hi, and thank You for the answer!

    Seems similar, but to be honest, I don't quite understand the post from the link. Anyway, if it is an already known issue and will be corrected - super!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.