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. Bad QGraphicsView rendering by combining QGraphicsProxyWidget and QGraphicsDropShadowEffect

Bad QGraphicsView rendering by combining QGraphicsProxyWidget and QGraphicsDropShadowEffect

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.1k Views
  • 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.
  • M Offline
    M Offline
    Michael Scopchanov
    wrote on last edited by
    #1

    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.

    MainWindow.h

    #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();
    
    protected:
    QLineEdit *w;
    QGraphicsProxyWidget *g;
    
    };
    
    class Form : public QWidget
    {
    public:
        explicit Form(QWidget *parent = 0);
        void setScene(QGraphicsScene *scene);
    
    private: QGraphicsView *view;
    };
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    public: explicit MainWindow(QWidget *parent = 0);
    };
    
    #endif // MAINWINDOW_H
    

    MainWindow.cpp

    #include "MainWindow.h"
    
    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
    {
        QGraphicsScene *scene = new QGraphicsScene(this);
    
        QGraphicsView *view = new QGraphicsView(this);
        view->setScene(scene);
    
        setCentralWidget(view);
    
        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);
        form->setScene(scene);
    
        for (int n = 0; n < 7; n++)
        {
            MyRect *r = new MyRect();
            r->setPos(20, 70*n + 50);
            scene->addItem(r);
        }
    }
    
    MyRect::MyRect()
    {
        setFlags(ItemIsSelectable | ItemIsMovable);
        setBrush(QBrush(QColor(Qt::blue)));
        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);
        layout->addWidget(view);
    
        setLayout(layout);
    
        QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect();
        effect->setOffset(0);
        effect->setColor(QColor(150, 150, 150));
        effect->setBlurRadius(5);
        setGraphicsEffect(effect); // Comment this: problem is gone, but no shadow
    }
    
    void Form::setScene(QGraphicsScene *scene)
    {
        view->setScene(scene);
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Michael Scopchanov
        wrote on last edited by
        #3

        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!

        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