这是我前面问题的继续“如何从左上角开始将小部件添加到gridlayout”感谢X.Jacobs解决了这个问题。。 现在我想删除所有小部件,并以相同的顺序重新创建相同的小部件,就像刷新小部件库一样。。 谢谢
好的,这是我的用户界面。。当我单击createPose按钮时,它将调用3 Def
1。在特定文件夹中创建txt文件
2。清除我的网格布局中的所有小部件
3。最后,根据tat特定文件夹中的文件数和文件名重新创建我的所有小部件,如添加小部件和刷新库。。但顺序和之前一样
self.connect(self.ui.CreatePose_pushButton, QtCore.SIGNAL("clicked()"), self.createPose)
def createPose(self):
# To get Posename from UI
self.__current_Posename = self.getPoseName()
Path = 'D:\\PoseLibrary\\'
# To Grab All files in tat Path
Poses = self.findAllFiles(Path, '.xml')
self.__NameSpace = self.ui.NameSpace_comboBox.currentText()
#To find HighestTrailingNumber to Increment the file name
if self.__current_Posename == "":
newSuffix = self.findHighestTrailingNumber(Poses, self.__Default_Posename) + 1
self.PoseName = self.__Default_Posename + str(newSuffix)
else:
self.PoseName = self.__current_Posename
# Creating XML and Icon files
open(Path + self.PoseName + '.xml','w').close()
icon = self.createIcon(self.PoseName, Path)
# open(Path + self.PoseName + '.png','w').close()
self.refreshPoseLibrary(Path)
self.ui.PoseName_lineEdit.clear()
def refreshPoseLibrary(self, Path ):
# First Clear all my buttons in gridlayout
self.deleteAll()
# get all file fromm the path dir
Files = self.getfiles_by_Date(Path)
Poses = self.findAllFiles(Files, '.xml')
# Create Btn
for Pose in Poses:
icon = Path + Pose + '.png'
self.icon.addPixmap(QtGui.QPixmap(icon), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.button = QtGui.QPushButton('')
self.button.setObjectName(Pose)
self.buttonGroup.addButton(self.button)
self.button.setIcon(self.icon)
self.button.setIconSize(QtCore.QSize(128, 128))
self.button.setMinimumSize(QtCore.QSize(128, 128))
self.button.setMaximumSize(QtCore.QSize(128, 128))
self.ui.gridLayout.addWidget(self.button)
self.button.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.connect(self.button, QtCore.SIGNAL('customContextMenuRequested(const QPoint&)'), self.popup)
def deleteAll(self):
while self.ui.gridLayout.count():
item = self.ui.gridLayout.takeAt(0)
widget = item.widget()
widget.deleteLater()
def getfiles_by_Date(self, dirpath):
Files = [s for s in os.listdir(dirpath)
if os.path.isfile(os.path.join(dirpath, s))]
Files.sort(key=lambda s: os.path.getmtime(os.path.join(dirpath, s)))
return Files
现在,我又添加了一个函数,可以按创建日期对文件夹文件进行排序。。现在,我的gridlayout按正确的顺序排列按钮。。但是按钮的位置在跳。。我也上传了我的截图
从布局中删除所有小部件如下所示:
相关问题 更多 >
编程相关推荐