In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article editor for you detailed introduction of "Python how to modify single-column QVBoxLayout for multi-column", detailed content, clear steps, details handled properly, I hope that this "Python how to modify single-column QVBoxLayout for multi-column" article can help you solve doubts, the following follow the editor's ideas slowly in-depth, together to learn new knowledge.
Replacing the layout of QWidget is not that simple, assigning another object to a variable that stores other layout references.
Self.layout = Foo () widget.setLayout (self.layout) self.layout = Bar ()
Objects are different from variables in that the object itself is the entity that performs the operation, but the variable is only the place where the object reference is stored. For example, the object may be a person and change our names, so if they change our names, it doesn't mean they change us as a person.
The solution is to use sip. Delete delete Q layout, and then set up a new layout:
Import sysfrom PyQt5.QtCore import pyqtSlotfrom PyQt5.QtWidgets import (QApplication, QHBoxLayout, QMainWindow, QPushButton, QVBoxLayout, QWidget ) import sipclass TestCase (QMainWindow): def _ init__ (self): super (). _ init__ () test = QWidget () self.setCentralWidget (test) layout = QVBoxLayout (test) for i in range (10): temp_btn = QPushButton (str (I)) temp_btn.pressed.connect (self.multi_col) layout .addWidget (temp_btn) @ pyqtSlot () def multi_col (self): cols = [QVBoxLayout () QVBoxLayout ()] old_layout = self.centralWidget () .layout () while old_layout.count (): child = old_layout.takeAt (0) widget = child.widget () if widget is not None: old_layout.removeItem (child) cols [0] .ad dWidget (widget) cols [1], cols [0] = cols [0] Cols [1] sip.delete (old_layout) lay = QHBoxLayout (self.centralWidget ()) lay.addLayout (cols [0]) lay.addLayout (cols [1]) def main (): app = QApplication (sys.argv) window = TestCase () window.show () app.exec_ () if _ name__ = = "_ _ main__": main () reads here This article "Python how to modify single-column QVBoxLayout to multiple columns" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.