I have a main parent widget and I want some layouts on top of the parent widget.
Initializing the layout using the parent widget will place the layout on top of the parent widget. I like it and would like to do it several times (left, top, bottom and right) for the same parent widget.
I used QGridLayout with different layouts, but this made the layouts resize and made them small. No matter what Overlay is added, the latter should be on top of other elements.
Below is a very simple example of what I want.
import sys
from PySide import QtGui, QtCore
class Overlay(QtGui.QBoxLayout):
"""Overlay widgets on a parent widget."""
def __init__(self, parent=None, location="left"):
super().__init__(QtGui.QBoxLayout.TopToBottom, parent)
if location == "left" or location == "right":
self.setDirection(QtGui.QBoxLayout.TopToBottom)
if location == "right":
self.setAlignment(QtCore.Qt.AlignRight)
elif location == "top" or location == "bottom":
self.setDirection(QtGui.QBoxLayout.LeftToRight)
if location == "bottom":
self.setAlignment(QtCore.Qt.AlignBottom)
self.css = "QWidget {background-color: lightskyblue; color: white}"
def addWidget(self, widget):
super().addWidget(widget)
widget.setStyleSheet(self.css)
def main():
app = QtGui.QApplication(sys.argv)
window = QtGui.QMainWindow()
window.show()
widg = QtGui.QTreeView()
window.setCentralWidget(widg)
left = Overlay(widg, "left")
left.addWidget(QtGui.QLabel("HELLO"))
left.addWidget(QtGui.QLabel("WORLD!"))
top = Overlay(widg, "top")
top.addWidget(QtGui.QLabel("Hello"))
top.addWidget(QtGui.QLabel("World!"))
right = Overlay(location="right")
right.setParent(widg)
right.addWidget(QtGui.QLabel("hello"))
right.addWidget(QtGui.QLabel("world!"))
return app.exec_()
if __name__ == '__main__':
sys.exit(main())
? , , Overlays ?
layout = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom, parent_widget)
,
layout = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom)
layout.setParent(parent_widget)
, ?