- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先,我是 python 和 pyside 的新手。
我有三个不同的 QTreeWidgets,代表三个不同的文件夹结构。当我尝试连续清除所有三个时,应用程序崩溃。
widgets = [ self.Delete_treeWidget01, self.Delete_treeWidget02, self.Delete_treeWidget03 ]
for widget in widgets:
widget.clear()
我也试过用其他方法清除它,例如
widgets = [ self.treeWidget01, self.treeWidget02, self.treeWidget03 ]
for widget in widgets:
aList = (range(widget.topLevelItemCount()))
for i in aList[::-1]:
widget.takeTopLevelItem(i)
这也使它以同样的方式崩溃。
我点击“调试”, Visual Studio 给了我这条信息:
Unhandled exception at 0x000000006E9D2C68 (QtGui4.dll) in mayapy.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
(它说是 maya,因为我正在使用带有 maya python 解释器的 eclipse,因为我主要为 maya 编写代码。然而,这是独立的,不涉及 maya。)
我删除了 QTreeWidgets 所代表的层次结构中的一个文件夹,为了让它再次准确显示,我想清除它以便再次填充它。
当我用谷歌搜索这个问题时,有人说它与线程有关,但由于我是 python 和 pyside 的新手,我什至不知道如何线程。
有人知道如何做到这一点吗?
编辑:
代码
import os
import sys
from PySide import QtGui, QtCore
from Toolbox_Test_UI import Ui_MirrorFolderCreation
from PySide.QtGui import QMainWindow, QApplication
class MainWindow( QMainWindow, Ui_MirrorFolderCreation ):
def __init__( self ):
super( MainWindow, self ).__init__()
self.setupUi( self )
# Connects the buttons
self.Delete_pushButton01.clicked.connect( lambda: self.folderDialog( 'delete1_dir' ) )
self.Delete_pushButton02.clicked.connect( lambda: self.folderDialog( 'delete2_dir' ) )
self.Delete_pushButton03.clicked.connect( lambda: self.folderDialog( 'delete3_dir' ) )
self.Delete_deletePushButton.clicked.connect( lambda: self.deleteFolders() )
self.Delete_populatePushButton.clicked.connect( lambda: self.populateTreeViews() )
self.Delete_treeWidget01.itemClicked.connect( lambda: self.findMirroredItem() )
# Change resize mode
headers = [self.Delete_treeWidget01.header(), self.Delete_treeWidget02.header(), self.Delete_treeWidget03.header()]
for head in headers:
head.setResizeMode( 0, QtGui.QHeaderView.ResizeToContents )
def findMirroredItem( self ):
''' find a item mirrored in widget 2 and 3 '''
#self.deselectTreeWidgetsItem()
widgets = [self.Delete_treeWidget02, self.Delete_treeWidget03]
for eachWidget in widgets:
self.selectMirroredItems(eachWidget)
def folderDialog( self, arg ):
''' Set lineEdits'''
dialog = QtGui.QFileDialog()
path = dialog.getExistingDirectory( self, "Select Folder", os.getcwd() )
if path:
if arg == 'delete1_dir':
self.Delete_lineEdit01.setText( path )
elif arg == 'delete2_dir':
self.Delete_lineEdit02.setText( path )
elif arg == 'delete3_dir':
self.Delete_lineEdit03.setText( path )
def populateTreeViews(self):
''' poplute the widgets'''
widgets = { self.Delete_treeWidget01:self.Delete_lineEdit01, self.Delete_treeWidget02:self.Delete_lineEdit02, self.Delete_treeWidget03:self.Delete_lineEdit03 }
for treeWidget, lineEdit in widgets.iteritems():
folderPath = lineEdit.text()
if folderPath:
treeWidget.clear()
self.populateTreeWidgetSearch( treeWidget, folderPath )
def populateTreeWidgetSearch( self, treeWidget, folderPath ):
rootTreeView = None
def searchFolder( folder, rootTreeView ):
folders = os.listdir( folder )
for eachSubFolder in folders:
childFolder = os.path.join( folder, eachSubFolder )
if os.path.isdir( childFolder ):
if rootTreeView is None:
rootTreeView = treeWidget.invisibleRootItem()
item = QtGui.QTreeWidgetItem( rootTreeView )
item.setText( 0, eachSubFolder )
item.setExpanded( True )
item.parent()
treeWidget.addTopLevelItem( item )
if os.listdir( childFolder ):
searchFolder( childFolder, item )
if folderPath:
searchFolder( folderPath, rootTreeView )
def deleteFolders( self ):
def countFolder( folder):
folders = os.listdir( folder )
for eachSubFolder in folders:
eachSubFolder = os.path.join( folder, eachSubFolder )
if os.path.isdir( eachSubFolder ):
self.foIndex += 1
if os.listdir( eachSubFolder ):
countFolder( eachSubFolder)
else:
self.fiIndex += 1
def findFolders():
folderPath = []
widgets = {self.Delete_treeWidget01:self.Delete_lineEdit01, self.Delete_treeWidget02:self.Delete_lineEdit02, self.Delete_treeWidget03:self.Delete_lineEdit03}
for treeWidget, lineEdit in widgets.iteritems():
selectedItems = treeWidget.selectedItems()
for item in selectedItems:
basePath = lineEdit.text()
if basePath:
treeWidgetHierarchy = self.getTreePath( item )
folderPath.append( os.path.join( basePath, treeWidgetHierarchy ) )
return folderPath
infoDict = []
for eachFolder in findFolders():
self.fiIndex = 0
self.foIndex = 0
countFolder( eachFolder)
infoDict.append({'deletionFolder':eachFolder, 'files':self.fiIndex, 'folders':self.foIndex})
self.populateTreeViews()
def deselectTreeWidgetsItem(self):
# Deselect everything from previews selection
widgets = [self.Delete_treeWidget02, self.Delete_treeWidget03]
for eachWidget in widgets:
for eachSel in eachWidget.selectedItems():
eachSel.setSelected( False )
def selectMirroredItems(self, widget):
# Get selected item
item = self.Delete_treeWidget01.selectedItems()[0]
# Path to the selected item
itemChilds = self.getTreePath( item )
# Find all top items to iterate through
topItems = widget.findItems( itemChilds.split( '/' )[0],QtCore.Qt.MatchExactly,0 )
# Default state of variables
itemFound = None
listCheck = []
index = 1
if topItems:
TreeWidgetItems = QtGui.QTreeWidgetItemIterator( topItems[0] )
TreeWidgetItemList = self.remakeList( TreeWidgetItems )
for child in itemChilds.split( '/' ):
index = index + 1
for item in TreeWidgetItemList:
itemlist = self.getTreePath( item )
if child == item.text( 0 ):
listCheck.append( item.text( 0 ))
if ( itemlist in itemChilds ) and ( len( itemChilds.split('/')) < index ):
itemFound = item
if itemFound:
widget.scrollToItem(itemFound)
itemFound.setSelected( True )
def remakeList(self, treeWidgetList):
itemList = []
for it in treeWidgetList:
itemList.append(it.value())
return itemList
def getTreePath( self, item ):
path = []
while item is not None:
path.append( str( item.text( 0 )))
item = item.parent()
return '/'.join( reversed( path ))
if __name__ == '__main__':
app = QApplication( sys.argv )
frame = MainWindow()
frame.show()
app.exec_()
窗口:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'C:/Users/stmahe1/GoogleDrive_Group3/TA_SpaceShooter/scripts/WIP/mattias/PipelineToolbox/Mirror/ui/Toolbox_Test.ui'
#
# Created: Tue Apr 08 13:19:23 2014
# by: pyside-uic 0.2.15 running on PySide 1.2.1
#
# WARNING! All changes made in this file will be lost!
from PySide import QtCore, QtGui
class Ui_MirrorFolderCreation(object):
def setupUi(self, MirrorFolderCreation):
MirrorFolderCreation.setObjectName("MirrorFolderCreation")
MirrorFolderCreation.resize(807, 626)
self.centralwidget = QtGui.QWidget(MirrorFolderCreation)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout_8 = QtGui.QVBoxLayout(self.centralwidget)
self.verticalLayout_8.setObjectName("verticalLayout_8")
self.verticalLayout_4 = QtGui.QVBoxLayout()
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.label_6 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setFamily("Orator Std")
font.setPointSize(11)
font.setWeight(75)
font.setBold(True)
self.label_6.setFont(font)
self.label_6.setObjectName("label_6")
self.verticalLayout_4.addWidget(self.label_6)
self.horizontalLayout_4 = QtGui.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.verticalLayout_6 = QtGui.QVBoxLayout()
self.verticalLayout_6.setObjectName("verticalLayout_6")
self.horizontalLayout_20 = QtGui.QHBoxLayout()
self.horizontalLayout_20.setObjectName("horizontalLayout_20")
self.Delete_lineEdit01 = QtGui.QLineEdit(self.centralwidget)
self.Delete_lineEdit01.setObjectName("Delete_lineEdit01")
self.horizontalLayout_20.addWidget(self.Delete_lineEdit01)
self.Delete_pushButton01 = QtGui.QPushButton(self.centralwidget)
self.Delete_pushButton01.setMaximumSize(QtCore.QSize(30, 16777215))
self.Delete_pushButton01.setObjectName("Delete_pushButton01")
self.horizontalLayout_20.addWidget(self.Delete_pushButton01)
self.verticalLayout_6.addLayout(self.horizontalLayout_20)
self.Delete_treeWidget01 = QtGui.QTreeWidget(self.centralwidget)
self.Delete_treeWidget01.setEnabled(True)
self.Delete_treeWidget01.setObjectName("Delete_treeWidget01")
self.Delete_treeWidget01.header().setVisible(False)
self.Delete_treeWidget01.header().setStretchLastSection(False)
self.verticalLayout_6.addWidget(self.Delete_treeWidget01)
self.horizontalLayout_4.addLayout(self.verticalLayout_6)
self.verticalLayout_5 = QtGui.QVBoxLayout()
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.horizontalLayout_19 = QtGui.QHBoxLayout()
self.horizontalLayout_19.setObjectName("horizontalLayout_19")
self.Delete_lineEdit02 = QtGui.QLineEdit(self.centralwidget)
self.Delete_lineEdit02.setObjectName("Delete_lineEdit02")
self.horizontalLayout_19.addWidget(self.Delete_lineEdit02)
self.Delete_pushButton02 = QtGui.QPushButton(self.centralwidget)
self.Delete_pushButton02.setMaximumSize(QtCore.QSize(30, 16777215))
self.Delete_pushButton02.setObjectName("Delete_pushButton02")
self.horizontalLayout_19.addWidget(self.Delete_pushButton02)
self.verticalLayout_5.addLayout(self.horizontalLayout_19)
self.Delete_treeWidget02 = QtGui.QTreeWidget(self.centralwidget)
self.Delete_treeWidget02.setObjectName("Delete_treeWidget02")
self.Delete_treeWidget02.headerItem().setText(0, "1")
self.Delete_treeWidget02.header().setVisible(False)
self.Delete_treeWidget02.header().setStretchLastSection(False)
self.verticalLayout_5.addWidget(self.Delete_treeWidget02)
self.horizontalLayout_4.addLayout(self.verticalLayout_5)
self.verticalLayout_7 = QtGui.QVBoxLayout()
self.verticalLayout_7.setObjectName("verticalLayout_7")
self.horizontalLayout_21 = QtGui.QHBoxLayout()
self.horizontalLayout_21.setObjectName("horizontalLayout_21")
self.Delete_lineEdit03 = QtGui.QLineEdit(self.centralwidget)
self.Delete_lineEdit03.setObjectName("Delete_lineEdit03")
self.horizontalLayout_21.addWidget(self.Delete_lineEdit03)
self.Delete_pushButton03 = QtGui.QPushButton(self.centralwidget)
self.Delete_pushButton03.setMaximumSize(QtCore.QSize(30, 16777215))
self.Delete_pushButton03.setObjectName("Delete_pushButton03")
self.horizontalLayout_21.addWidget(self.Delete_pushButton03)
self.verticalLayout_7.addLayout(self.horizontalLayout_21)
self.Delete_treeWidget03 = QtGui.QTreeWidget(self.centralwidget)
self.Delete_treeWidget03.setObjectName("Delete_treeWidget03")
self.Delete_treeWidget03.headerItem().setText(0, "1")
self.Delete_treeWidget03.header().setVisible(False)
self.verticalLayout_7.addWidget(self.Delete_treeWidget03)
self.horizontalLayout_4.addLayout(self.verticalLayout_7)
self.verticalLayout_4.addLayout(self.horizontalLayout_4)
self.horizontalLayout_5 = QtGui.QHBoxLayout()
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.Delete_populatePushButton = QtGui.QPushButton(self.centralwidget)
self.Delete_populatePushButton.setObjectName("Delete_populatePushButton")
self.horizontalLayout_5.addWidget(self.Delete_populatePushButton)
spacerItem = QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_5.addItem(spacerItem)
self.Delete_deletePushButton = QtGui.QPushButton(self.centralwidget)
self.Delete_deletePushButton.setObjectName("Delete_deletePushButton")
self.horizontalLayout_5.addWidget(self.Delete_deletePushButton)
self.verticalLayout_4.addLayout(self.horizontalLayout_5)
self.verticalLayout_8.addLayout(self.verticalLayout_4)
self.gridLayout_4 = QtGui.QGridLayout()
self.gridLayout_4.setObjectName("gridLayout_4")
self.verticalLayout_8.addLayout(self.gridLayout_4)
MirrorFolderCreation.setCentralWidget(self.centralwidget)
self.actionExit = QtGui.QAction(MirrorFolderCreation)
self.actionExit.setObjectName("actionExit")
self.actionLoad_preset = QtGui.QAction(MirrorFolderCreation)
self.actionLoad_preset.setObjectName("actionLoad_preset")
self.actionSave_Preset = QtGui.QAction(MirrorFolderCreation)
self.actionSave_Preset.setObjectName("actionSave_Preset")
self.retranslateUi(MirrorFolderCreation)
QtCore.QMetaObject.connectSlotsByName(MirrorFolderCreation)
MirrorFolderCreation.setTabOrder(self.Delete_lineEdit01, self.Delete_lineEdit02)
MirrorFolderCreation.setTabOrder(self.Delete_lineEdit02, self.Delete_lineEdit03)
MirrorFolderCreation.setTabOrder(self.Delete_lineEdit03, self.Delete_pushButton01)
MirrorFolderCreation.setTabOrder(self.Delete_pushButton01, self.Delete_pushButton02)
MirrorFolderCreation.setTabOrder(self.Delete_pushButton02, self.Delete_pushButton03)
MirrorFolderCreation.setTabOrder(self.Delete_pushButton03, self.Delete_populatePushButton)
MirrorFolderCreation.setTabOrder(self.Delete_populatePushButton, self.Delete_deletePushButton)
MirrorFolderCreation.setTabOrder(self.Delete_deletePushButton, self.Delete_treeWidget01)
MirrorFolderCreation.setTabOrder(self.Delete_treeWidget01, self.Delete_treeWidget02)
MirrorFolderCreation.setTabOrder(self.Delete_treeWidget02, self.Delete_treeWidget03)
def retranslateUi(self, MirrorFolderCreation):
MirrorFolderCreation.setWindowTitle(QtGui.QApplication.translate("MirrorFolderCreation", "Technical Artist Toolbox", None, QtGui.QApplication.UnicodeUTF8))
self.label_6.setText(QtGui.QApplication.translate("MirrorFolderCreation", "Mirrored Deletion of Folders", None, QtGui.QApplication.UnicodeUTF8))
self.Delete_pushButton01.setText(QtGui.QApplication.translate("MirrorFolderCreation", "...", None, QtGui.QApplication.UnicodeUTF8))
self.Delete_pushButton02.setText(QtGui.QApplication.translate("MirrorFolderCreation", "...", None, QtGui.QApplication.UnicodeUTF8))
self.Delete_pushButton03.setText(QtGui.QApplication.translate("MirrorFolderCreation", "...", None, QtGui.QApplication.UnicodeUTF8))
self.Delete_populatePushButton.setText(QtGui.QApplication.translate("MirrorFolderCreation", "Update", None, QtGui.QApplication.UnicodeUTF8))
self.Delete_deletePushButton.setText(QtGui.QApplication.translate("MirrorFolderCreation", "Delete", None, QtGui.QApplication.UnicodeUTF8))
self.actionExit.setText(QtGui.QApplication.translate("MirrorFolderCreation", "Exit", None, QtGui.QApplication.UnicodeUTF8))
self.actionLoad_preset.setText(QtGui.QApplication.translate("MirrorFolderCreation", "Load Preset", None, QtGui.QApplication.UnicodeUTF8))
self.actionSave_Preset.setText(QtGui.QApplication.translate("MirrorFolderCreation", "Save Preset", None, QtGui.QApplication.UnicodeUTF8))
经过一些进一步的测试,这可能是因为我在小部件中选择了一些东西,(发现如果我不运行 findMirroredItem() 它会起作用)但是它无助于取消选择先取消选择所有内容。
如果我单击第一个小部件,它会尝试在其他两个小部件中选择一个相似的对象。如果我不点击第一个小部件,我可以重新加载/填充它多少次我想要它不会崩溃。如果我选择了一些东西,如果我尝试重新加载/填充它,它最终会崩溃。
最佳答案
这似乎是由 QTreeWidgetItemIterator
中的 PySide 错误引起的,当传递 QTreeWidgetItem
作为第一个参数时。当 QTreeWidget
作为第一个参数传递时,问题就消失了。等效的 PyQt4 代码不会出现此错误。
可以通过修改 selectMirroredItems
中的以下行来修复示例代码:
# TreeWidgetItems = QtGui.QTreeWidgetItemIterator( topItems[0] )
TreeWidgetItems = QtGui.QTreeWidgetItemIterator(widget)
似乎简单地遍历 QTreeWidgetItemIterator
就足以导致段错误(尽管我没有尝试创建最小测试用例)。
可以报告 PySide 错误 here .
关于python - PySide QTreeWidget clear() 导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22934043/
谁能告诉我为什么 的技术原因在 app.config 与 中无效 通常这样使用: 问题是我正在使用安装程序产品 (InstallShield) 将 xml 转换为 app.config
在Linux上,使用崇高的文本。Os.system(‘Clear’)应该只清除控制台窗口。用于Windows的os.system(‘cls’)。但它回来的时候和我不一样。。代码:。退货:。为什么在Cl
这个问题在这里已经有了答案: How can I force the STL memory cache to clear? (2 个答案) 关闭 6 年前。 我在 Solaris 10 上使用 g+
official docs关于 .clear() 我不是很清楚。他们说: Erases all AsyncStorage for all clients, libraries, etc. You pr
我有这段代码可以清除 C# WebBrowser 控件中的缓存。它的问题是它还会清除 cookie。在整个互联网上,我似乎是唯一一个不想这样的人。 我需要维护 cookie,但要丢弃缓存。 特别感兴趣
我记得直接在 DataTable 上调用的一些方法/属性之间存在差异。类,以及 DataTable.Rows 上同名的方法/属性属性(property)。 (可能是我读到这篇文章的 RowCount/
在 Unity 的 Camera组件中有一个属性清除标志,它允许从四个选项中进行选择:天空盒、纯色、仅深度和不清除。 正如文档所说: Don’t clear This mode does not cl
我无法找出为什么我的函数没有被调用。我将 alert("test") 放在那里只是为了测试函数是否被调用,而事实并非如此。 HTML: JS: function clear(price,quanti
我有 2 个数组列表: ArrayList> res= new ArrayList(); ArrayList data= new ArrayList(); 在我将结果集添加到子项并将子项附加到父项后,
正如主题所述..哪个版本更有效,为什么? std::vector a; .. a.clear(); 或 std::vector a; .. if(!a.empty()) a.clear(); 最佳
我包含了定义函数“clear()”的“PDCurses/curses.h”,然后当我使用“std::wstring::clear()”时,msvc-10.0 编译器报告错误。当我在包含后使用“#und
Session.Clear() 与 Session.Contents.Clear() 有什么区别? 我想清除所有 session 变量。 谢谢。 最佳答案 根据反射器,没有差异。 Session.Co
QPointer有一个方法, clear() . Clears this QPointer object. 我不确定“清晰”的确切含义。在我看来,这可能意味着 它会删除您引用的指针。 或 它取消附加您
在 string::clear 函数的描述中,它说: clear: Erases the contents of the string, which becomes an empty string (
我有两个不同的 Mathematica 笔记本,它们具有相似但功能不同的功能。当它们是唯一打开的笔记本时,两者都可以正常工作。尽管我(自由地)使用 Clear[] 来清除相关变量,但其中一个在另一个笔
有没有办法扩展 Symfony 2 cache:clear命令来清除 APC 还是执行一些其他逻辑? 最佳答案 您可以使用 ApcBundle去做这个。 关于php - 扩展 Symfony 2 缓存
我正在尝试使用 html 和 css 制作一个简单的信息网站,并使用 960 网格,因为该网站将具有分栏结构。 当我将标题 h1 float 到左侧(它有 Logo 图像,我正在使用 css 添加图像
我刚刚意识到: 在一系列 float div 导致布局破坏之后,同时 工作正常。 谁能解释一下? 这是 CSS: div.clear { clear:both; } 最佳答案 如果您将
这两个命令等效吗?如果不是,有什么区别? 最佳答案 rake 任务仅清除存储在文件系统 "#{Rails.root}/tmp/cache" 中的文件。这是该任务的代码。 namespace :cach
在STM32F407上初始化USART1时,我在启用TC中断时遇到了问题。一旦 USART RCC 启用,SR 中的 Tcflags就会被设置(“1”),而在启用 TC 中断之前清除该标志对我来说已经
我是一名优秀的程序员,十分优秀!