1

I want to overlap widgets and make them all functional, but I can't get this done through simple layout management. I found an example applying a mask over the widget, but is in C++ and I am having a hard time trying to port it to python.

The example is in this article:

That's exactly what I need, and I'm trying to implement it in my code. But I get the error:

NotImplementedError: reverse operator not implemented

How could I solve this?

A very simple example of what I'm doing in the code:

from PySide import QtCore as qc
from PySide import QtGui as qg
import operator
###############################################################
class WinDin(qg.QDialog):
    def __init__(self):
        super(WinDin, self).__init__()
        self.setLayout(qg.QVBoxLayout())
        self.setFixedSize(500,500)

        button_00 = qg.QPushButton('death')
        self.layout().addWidget(button_00)

        ##################################################
        # IM USING A QLABEL FOR EASY LOOK THROUGH ...
        #
        self._mainWidget = qg.QLabel(self)
        self._mainWidget.setFixedSize(500,500)
        self._mainWidget.setStyleSheet("background-color: rgba(255,0,0,5)")

        lay_out = qg.QHBoxLayout(self._mainWidget)
        button_01 = qg.QPushButton('trick')

        lay_out.setAlignment(qc.Qt.AlignBottom)
        lay_out.addWidget(button_01)

        self.settingMask()
    ############################################################################################################################################
    def settingMask(self):
        ### SAW THIS EXAMPLE IN OTHER FORO IN C++

        frame_geometry = self._mainWidget.frameGeometry()
        wd_geo = self._mainWidget.geometry()
        child_reg = self._mainWidget.childrenRegion()


        ##############################
        # TESTING WITH OPERATOR MODULE I GET AND ERRROR . 'PySide.QtCore.QRect' is not iterable
        #
        #this = operator.__contains__(wd_geo,wd_geo)
        #self._mainWidget.setMask(this)

        self._mainWidget.setMask(frame_geometry - child_reg)

        ###
        ###
        ###  THIS WAY I GET : NotImplementedError: reverse operator not implemented.

##########################################
def main():
    import sys
    qtApp=qg.QApplication(sys.argv)
    myWinPos=WinDin()
    myWinPos.show()
    sys.exit(qtApp.exec_())

if __name__=="__main__":
    main()

How can I subtract the children geometry from the parent and make it work?

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Nestor Colt
  • 379
  • 4
  • 18

1 Answers1

1

You need to use the QRegion class to get this to work:

def settingMask(self):
    region = qg.QRegion(self._mainWidget.frameGeometry())
    region -= qg.QRegion(self._mainWidget.geometry())
    region += self._mainWidget.childrenRegion()
    self._mainWidget.setMask(region)

Also, on my system (Linux), I found I had to call this after the window is shown:

def main():
    ...
    myWinPos.show()
    myWinPos.settingMask()
    sys.exit(qtApp.exec_())
ekhumoro
  • 115,249
  • 20
  • 229
  • 336