我使用pyqt设计器创建了两个.ui文件:一个是主窗口,另一个是Widget。每当我尝试将小部件添加到主窗口中的滚动区域时,它都不会显示在屏幕上,而且我也不知道为什么。
很抱歉,如果这是一个愚蠢的问题,我仍在学习pyqt5和pyqt设计器。任何帮助将不胜感激,谢谢。
代码:
namespace Assets.Areas.Clinical.Models
{
public class ClinicalPAT
{
[Key]
public int ClinicalPATID { get; set; }
public int ClinicalAssetID { get; set; }
public DateTime? WarrantyEndDate { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:ddd/MMMM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? InspectionDate { get; set; }
public int? InspectionOutcomeID { get; set; }
[StringLength(100, MinimumLength = 2)]
public string InspectionDocumnets { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:ddd/MMMM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? InspectionDueDate { get; set; }
public virtual InspectionOutcome InspectionOutcomeResult { get; set; }
}
}
Ui_Reddit:
class Window(QMainWindow):
def __init__(self):
super(Window,self).__init__()
self.ui=Ui_Reddit()
self.ui.setupUi(self)
self.setStyle(QStyleFactory.create('Cleanlooks'))
#self.setGeometry(300, 300, 600, 600)
self.setWindowTitle("Reddit")
self.show()
self.mainWindow()
def mainWindow(self):
#to handle all the api calls using praw
self.x = RedditApi()
self.printSubmissions()
def printSubmissions(self):
#Gets the list of all submission titles to be displayed
#TO DO: Get and add other things like points and comments
self.submissions = self.x.showSubmissions()
for submission in self.submissions:
card = QWidget()
card_ui = Ui_Card()
card_ui.setupUi(card)
card_ui.title.setText(submission)
self.ui.verticalLayout_2.addWidget(card)
Ui_Card:
class Ui_Reddit(object):
def setupUi(self, Reddit):
Reddit.setObjectName("Reddit")
Reddit.resize(800, 600)
Reddit.setTabShape(QtWidgets.QTabWidget.Rounded)
self.centralwidget = QtWidgets.QWidget(Reddit)
self.centralwidget.setObjectName("centralwidget")
self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea.setGeometry(QtCore.QRect(10, 60, 781, 531))
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 779,
529))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.verticalLayoutWidget_2 =
QtWidgets.QWidget(self.scrollAreaWidgetContents)
self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(-1, -1, 811,
551))
self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
self.verticalLayout_2 =
QtWidgets.QVBoxLayout(self.verticalLayoutWidget_2)
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(0, 0, 801, 51))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.horizontalLayout =
QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtWidgets.QLabel(self.horizontalLayoutWidget)
self.label.setIndent(5)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.comboBox = QtWidgets.QComboBox(self.horizontalLayoutWidget)
self.comboBox.setObjectName("comboBox")
self.horizontalLayout.addWidget(self.comboBox)
spacerItem = QtWidgets.QSpacerItem(40, 20,
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.search_bar = QtWidgets.QLineEdit(self.horizontalLayoutWidget)
self.search_bar.setText("")
self.search_bar.setObjectName("search_bar")
self.horizontalLayout.addWidget(self.search_bar)
self.pushButton = QtWidgets.QPushButton(self.horizontalLayoutWidget)
self.pushButton.setFlat(False)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout.addWidget(self.pushButton)
spacerItem1 = QtWidgets.QSpacerItem(40, 20,
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem1)
Reddit.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(Reddit)
self.statusbar.setObjectName("statusbar")
Reddit.setStatusBar(self.statusbar)
self.retranslateUi(Reddit)
QtCore.QMetaObject.connectSlotsByName(Reddit)
def retranslateUi(self, Reddit):
_translate = QtCore.QCoreApplication.translate
Reddit.setWindowTitle(_translate("Reddit", "MainWindow"))
self.label.setText(_translate("Reddit", "TextLabel"))
self.search_bar.setPlaceholderText(_translate("Reddit", "Search"))
self.pushButton.setText(_translate("Reddit", "PushButton"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Reddit = QtWidgets.QMainWindow()
ui = Ui_Reddit()
ui.setupUi(Reddit)
Reddit.show()
sys.exit(app.exec_())