1

I have tested customized QGraphicsEffect and founded a weird case.
I applied the EFFECT on my dialog and it does not work in QListView.

Here is simple test,

from PySide2.QtCore import Qt, QPoint
from PySide2.QtWidgets import QDialog, QGraphicsEffect, QVBoxLayout, QHBoxLayout, QPushButton, QApplication, QListView, QTreeView, QTableView
from PySide2.QtGui import QTransform
import sys

class DarkenEffect(QGraphicsEffect):
    def draw(self, painter):
        offset = QPoint()
        if self.sourceIsPixmap():
            pixmap = self.sourcePixmap(Qt.LogicalCoordinates, offset)
        else:
            pixmap = self.sourcePixmap(Qt.DeviceCoordinates, offset)
            painter.setWorldTransform(QTransform())

        painter.setBrush(Qt.black)
        painter.drawRect(pixmap.rect())
        painter.setOpacity(0.5)
        painter.drawPixmap(offset, pixmap)  

class Dialog(QDialog):
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        self.setupUi()

        effect = DarkenEffect(self)
        self.setGraphicsEffect(effect)

    def setupUi(self):
        layout = QVBoxLayout()
        self.setLayout(layout)
        listview = QListView()
        layout.addWidget(listview)
        treeview = QTreeView()
        layout.addWidget(treeview)
        tableview = QTableView()
        layout.addWidget(tableview)
        button1 = QPushButton("BUTTON1")
        layout.addWidget(button1)
        button2 = QPushButton("BUTTON2")
        layout.addWidget(button2)
        hLayout = QHBoxLayout()
        button3 = QPushButton("BUTTON3")
        hLayout.addWidget(button3)
        button4 = QPushButton("BUTTON4")
        hLayout.addWidget(button4)
        layout.addLayout(hLayout)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    dlg = Dialog()
    dlg.show()
    sys.exit(app.exec_())

after running the test code, when mouse cursor above the QListView or QTreeView, the effect disappears. But above the QTableView, it keeps on.
I just wonder if there is any difference between QListView and QTableView.

Hyun-geun Kim
  • 919
  • 3
  • 22
  • 37
  • I tried it with PySide2 5.9.0 and the behavior is as follows: initially the TreeView, QTableView and ListView are not affected by the effect, just when I change the size of the window the effect is seen in those elements, then when I move the mouse it stays fine, also when I press some of the XXXView it remains if I just press the same element, if I change the effect is removed in 2 of them, and when I press the one that maintains the effect it is also removed. In the case of the buttons, this works correctly. – eyllanesc May 08 '18 at 09:20
  • @eyllanesc Yes, when has focus, all 3 views are losing the effect. That's what I missed. But, I hope all views to be applied the effect in all circumstances. – Hyun-geun Kim May 08 '18 at 09:31

0 Answers0