我在这里遇到问题。我基本上是想一次显示QVBoxLayout中的每个小部件。
创建每一行的过程已成功完成。但是,似乎一旦尝试使用self.showMaximized()
显示主窗口,程序就会冻结。考虑到我试图显示400行,并且每行中都包含大约50个小部件,所以我试图一次显示很多小部件,因此我猜想GUI对此没有响应。可行的解决方案是什么?
这是MainWindow类中导致程序冻结的代码片段:
def display_results(self):
# Menu Bar
self.menubar = QMenuBar()
self.main_layout.addWidget(self.menubar)
#Aggiungi menu per oottenere lo storico delle reviews
Ratings_menu = self.menubar.addMenu("Valutazioni")
get_negative_ratings = QAction("Ottieni ratings in calo", self)
get_negative_ratings.triggered.connect(lambda x: self.execute_negative_ratings_dialog())
Ratings_menu.addAction(get_negative_ratings)
get_positive_ratings = QAction("Ottieni ratings in crescita", self)
get_positive_ratings.triggered.connect(lambda x: self.execute_positive_ratings_dialog())
Ratings_menu.addAction(get_positive_ratings)
# Aggiungi menu per ordinare i risultati
sort_menu = self.menubar.addMenu("Ordina")
#Ordina avendo gli alpha piu negativi in cima
sort_highest_delta_price = QAction("Prodotti con prezzi competitors piu bassi prima", self)
sort_highest_delta_price.triggered.connect(self.sort_widgets_highest_delta_price_first)
sort_menu.addAction(sort_highest_delta_price)
#Ordina avendo i pilogico piu negativi in cima
sort_lowest_delta_reviews = QAction("Prodotti con competitors con magior numero di recensioni prima", self)
sort_lowest_delta_reviews.triggered.connect(self.sort_widgets_lowest_delta_reviews_first)
sort_menu.addAction(sort_lowest_delta_reviews)
self.rows = []
for search in self.searches:
search_widget = SearchResultWidget(search)
self.controls_layout.addWidget(search_widget)
self.rows.append(search_widget)
spacer = QSpacerItem(1, 1, QSizePolicy.Minimum, QSizePolicy.Expanding)
self.controls_layout.addItem(spacer)
self.controls.setLayout(self.controls_layout)
self.scroll.setWidget(self.controls)
self.main_layout.addWidget(self.searchbar, alignment=Qt.AlignTop)
self.main_layout.addWidget(self.scroll)
self.main_widget.setLayout(self.main_layout)
self.setCentralWidget(self.main_widget)
self.showMaximized()