我想根据窗口宽度动态更改overviewSummaryGroupBox的宽度(位于overview_gui.py文件中第三个代码框的开头),以便它很好地进入屏幕,而不是像给定的图片那样。 它在我的主 1920,1080 屏幕上工作,有一定效果,但数字仍然被剪掉,在我的 MacBook 上则不然,图片在我的 MacBook 屏幕上。
这意味着各个分组框中的小部件会更加紧密地结合在一起,如果一切都很好并且它们可以支持至少 10 位数字,那就很好。
这是代码:
from PySide6.QtWidgets import (QWidget, QGroupBox, QHBoxLayout, QLabel, QLCDNumber, QGridLayout)
class OverviewGui():
def __init__(self) -> None:
super().__init__()
def Gui(self):
self.overviewMainWidget = QWidget()
self.overviewMainLayout = QGridLayout(self.overviewMainWidget)
self.overviewMainLayout.setContentsMargins(0, 0, 0, 0)
# add summary groupbox
self.overviewMainLayout.addWidget(OverviewGui().Summary(), 0, 0)
return self.overviewMainWidget
def Summary(self):
self.overviewSummaryGroupBox = QGroupBox("Summary")
self.overviewSummaryLayout = QGridLayout(self.overviewSummaryGroupBox)
self.summaryNetworthGroupBox = QGroupBox()
self.summaryNetworthLayout = QHBoxLayout(self.summaryNetworthGroupBox)
self.summaryNetworthLabel = QLabel("Networth: ")
self.summaryNetworthLayout.addWidget(self.summaryNetworthLabel)
self.summaryNetworthValue = QLCDNumber()
self.summaryNetworthValue.setStyleSheet("border: 0px;")
self.summaryNetworthValue.setDigitCount(20)
self.summaryNetworthValue.display(12657479.00)
self.summaryNetworthValue.setSegmentStyle(self.summaryNetworthValue.segmentStyle().Flat)
self.summaryNetworthLayout.addWidget(self.summaryNetworthValue)
#self.summaryNetworthGroupBox.setFixedWidth(100)
self.summaryNetworthLayout.setSpacing(0)
self.overviewSummaryLayout.addWidget(self.summaryNetworthGroupBox, 0, 0)
self.summaryTotalAssetsGroupBox = QGroupBox()
self.summaryTotalAssetsLayout = QHBoxLayout(self.summaryTotalAssetsGroupBox)
self.summaryTotalAssetsLabel = QLabel("Total Assets: ")
self.summaryTotalAssetsLayout.addWidget(self.summaryTotalAssetsLabel)
self.summaryTotalAssetsValue = QLCDNumber()
self.summaryTotalAssetsValue.setStyleSheet("border: 0px;")
self.summaryTotalAssetsValue.setDigitCount(20)
self.summaryTotalAssetsValue.display(12657479.00)
self.summaryTotalAssetsValue.setSegmentStyle(self.summaryTotalAssetsValue.segmentStyle().Flat)
self.summaryTotalAssetsLayout.addWidget(self.summaryTotalAssetsValue)
self.overviewSummaryLayout.addWidget(self.summaryTotalAssetsGroupBox, 0, 1)
self.summaryTotalLiabilitiesGroupBox = QGroupBox()
self.summaryTotalLiabilitiesLayout = QHBoxLayout(self.summaryTotalLiabilitiesGroupBox)
self.summaryTotalLiabilitiesLabel = QLabel("Total Liabilities: ")
self.summaryTotalLiabilitiesLayout.addWidget(self.summaryTotalLiabilitiesLabel)
self.summaryTotalLiabilitiesValue = QLCDNumber()
self.summaryTotalLiabilitiesValue.setStyleSheet("border: 0px;")
self.summaryTotalLiabilitiesValue.setDigitCount(20)
self.summaryTotalLiabilitiesValue.display(12657479.00)
self.summaryTotalLiabilitiesValue.setSegmentStyle(self.summaryTotalLiabilitiesValue.segmentStyle().Flat)
self.summaryTotalLiabilitiesLayout.addWidget(self.summaryTotalLiabilitiesValue)
self.overviewSummaryLayout.addWidget(self.summaryTotalLiabilitiesGroupBox, 0, 2)
self.summaryTotalCashGroupBox = QGroupBox()
self.summaryTotalCashLayout = QHBoxLayout(self.summaryTotalCashGroupBox)
self.summaryTotalCashLabel = QLabel("Total Cash: ")
self.summaryTotalCashLayout.addWidget(self.summaryTotalCashLabel)
self.summaryTotalCashValue = QLCDNumber()
self.summaryTotalCashValue.setStyleSheet("border: 0px;")
self.summaryTotalCashValue.setDigitCount(20)
self.summaryTotalCashValue.display(12657479.00)
self.summaryTotalCashValue.setSegmentStyle(self.summaryTotalCashValue.segmentStyle().Flat)
self.summaryTotalCashLayout.addWidget(self.summaryTotalCashValue)
self.overviewSummaryLayout.addWidget(self.summaryTotalCashGroupBox, 0, 3)
self.summaryTotalMobileGroupBox = QGroupBox()
self.summaryTotalMobileLayout = QHBoxLayout(self.summaryTotalMobileGroupBox)
self.summaryTotalMobileLabel = QLabel("Total Mobile: ")
self.summaryTotalMobileLayout.addWidget(self.summaryTotalMobileLabel)
self.summaryTotalMobileValue = QLCDNumber()
self.summaryTotalMobileValue.setStyleSheet("border: 0px;")
self.summaryTotalMobileValue.setDigitCount(20)
self.summaryTotalMobileValue.display(12657479.00)
self.summaryTotalMobileValue.setSegmentStyle(self.summaryTotalMobileValue.segmentStyle().Flat)
self.summaryTotalMobileLayout.addWidget(self.summaryTotalMobileValue)
self.overviewSummaryLayout.addWidget(self.summaryTotalMobileGroupBox, 0, 4)
self.summaryTotalImmobileGroupBox = QGroupBox()
self.summaryTotalImmobileLayout = QHBoxLayout(self.summaryTotalImmobileGroupBox)
self.summaryTotalImmobileLabel = QLabel("Total Immobile: ")
self.summaryTotalImmobileLayout.addWidget(self.summaryTotalImmobileLabel)
self.summaryTotalImmobileValue = QLCDNumber()
self.summaryTotalImmobileValue.setStyleSheet("border: 0px;")
self.summaryTotalImmobileValue.setDigitCount(20)
self.summaryTotalImmobileValue.display(12657479.00)
self.summaryTotalImmobileValue.setSegmentStyle(self.summaryTotalImmobileValue.segmentStyle().Flat)
self.summaryTotalImmobileLayout.addWidget(self.summaryTotalImmobileValue)
self.overviewSummaryLayout.addWidget(self.summaryTotalImmobileGroupBox, 0, 5)
self.overviewSummaryGroupBox.setFixedHeight(self.overviewSummaryGroupBox.sizeHint().height())
return self.overviewSummaryGroupBox