Python Forum
[PyQt] How to clip layout to sides and bottom of main window?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] How to clip layout to sides and bottom of main window?
#4
Use this simple program to get a feel for how the HBox and VBox layout widgets work. Start by commenting out the "setStretch" commands and see how the labels are positioned as you stretch the window. Then uncomment the "content.setStretch" command to pin the "Left" and "Right" labels to the bottom of the screen.
import sys
import PySide2.QtWidgets as Qt

class MyWindow(Qt.QWidget):
    def __init__(self):
        super().__init__()
        content = Qt.QVBoxLayout(self)
        content.addWidget(Qt.QLabel('This is the main body'))
        row = Qt.QHBoxLayout()
        content.addLayout(row)
        row.addWidget(Qt.QLabel('Left Side'))
        row.addWidget(Qt.QLabel('Right Side'))

        # Up to now the different screen regions all resize proportionally

        # This makes the row stick to the bottom of the window.  It does this
        # by giving all the vertical "stretch" to the "main body" label
        content.setStretch(0, 1)

        # This does the same thing for the horizontal stretch of the bottom row
        row.setStretch(1, 1)

app = Qt.QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())
If you use QGridLayout you can get the same kind of effect by setting setColumnStretch and setRowStretch.
Reply


Messages In This Thread
RE: How to clip layout to sides and bottom of main window? - by deanhystad - Mar-24-2021, 01:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 608 Mar-17-2024, 09:37 AM
Last Post: deanhystad
Exclamation [Tkinter] Error when closing the main window with destroy TomasSanchexx 1 820 Aug-06-2023, 01:54 AM
Last Post: deanhystad
  [PyGUI] How to reuse a window layout based on mysql rowcount? retroisbest 2 2,485 Nov-09-2021, 09:02 AM
Last Post: retroisbest
  [PyQt] Can't get MDIarea to resize automatically with Main Window JayCee 4 3,521 Aug-02-2021, 08:47 PM
Last Post: JayCee
  "tkinter.TclError: NULL main window" Rama02 1 5,908 Feb-04-2021, 06:45 PM
Last Post: deanhystad
  pyqt5 layout Nickd12 8 3,594 Jan-18-2021, 09:09 AM
Last Post: Axel_Erfurt
  [Tkinter] Hi, Keep postition of main window after iconify() delphinis 3 3,146 Jul-12-2020, 06:59 AM
Last Post: DT2000
  [Tkinter] Auto re-fit frames sizes in main window Gilush 2 2,688 Jun-06-2020, 03:14 AM
Last Post: Gilush
  [Tkinter] How to add multiple frames to main window Dandy_Don 13 8,121 Apr-29-2020, 09:21 PM
Last Post: Dandy_Don
  tkinter window and turtle window error 1885 3 6,791 Nov-02-2019, 12:18 PM
Last Post: 1885

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020