python - 如何访问作为 List 中的 Box 的小部件
问题描述
在下面的代码中,我正在访问垂直滚动列表,并且 e 设置为我之后的条目。
我认为这只是一个具有 2 个小部件的 QHLayout 的小部件,但我尝试访问失败。
通过下面的尝试,我得到 builtin_function_or_method' 对象没有属性 'hbox
class GDMLColourMapEntry(QtGui.QWidget) :
def __init__(self,colour,material) :
super().__init__()
print('Map Entry : '+str(colour))
self.colour = colour
self.hbox = QtGui.QHBoxLayout()
self.hbox.addWidget(GDMLColour(colour))
self.hbox.addWidget(material)
self.setLayout(self.hbox)
def dataPicker(self):
print('DataPicker')
class GDMLColourMapList(QtGui.QScrollArea) :
def __init__(self,matList) :
super().__init__()
# Scroll Area which contains the widgets, set as the centralWidget
# Widget that contains the collection of Vertical Box
selfwidget = QtGui.QWidget()
self.matList = matList
# The Vertical Box that contains the Horizontal Boxes of labels and buttons
self.vbox = QtGui.QVBoxLayout()
self.widget.setLayout(self.vbox)
#Scroll Area Properties
self.setVerticalScrollBarPolicy(QtGui.Qt.ScrollBarAlwaysOn)
self.setHorizontalScrollBarPolicy(QtGui.Qt.ScrollBarAlwaysOff)
self.setWidgetResizable(True)
self.setWidget(self.widget)
def addEntry(self, colour) :
print('Add Entry')
mat = GDMLMaterial(self.matList)
self.vbox.addWidget(GDMLColourMapEntry(colour,mat))
class GDMLColourMap(QtGui.QDialog) :
#class GDMLColourMap(QtGui.QMainWindow) :
def __init__(self, parent) :
super(GDMLColourMap, self).__init__(parent, QtCore.Qt.Tool)
self.initUI()
def initUI(self):
self.result = userCancelled
# create our window
# define window xLoc,yLoc,xDim,yDim
self.setGeometry( 250, 250, 550, 350)
self.setWindowTitle("Map FreeCAD Colours to GDML Materials")
self.setMouseTracking(True)
lay = QtGui.QGridLayout(self)
materialList = self.getGDMLMaterials()
self.mapList = GDMLColourMapList(materialList)
mat = GDMLMaterial(self.matList)
self.vbox.addWidget(GDMLColourMapEntry(colour,mat))
def lookupColour(self, col) :
print('Lookup Colour')
idx = self.colorList.index(col)
print(idx)
e = self.mapList.vbox.itemAt(idx)
print(e)
f = e.hbox.itemAt(1)
print(f)
return(255)
解决方案
固定与
def lookupColour(self, col) :
print('Lookup Colour')
idx = self.colorList.index(col)
print(idx)
entry = self.mapList.vbox.itemAt(idx).widget()
print(entry)
mat = entry.hbox.itemAt(1).widget().currentText()
print(mat)
return mat
推荐阅读
- php - ErrorException:间接修改重载属性 App\Answer::$attribute 无效
- java - 使用 SimpleDateFormat 格式化日期时抛出 ClassCastException
- c# - 从android java返回字节数组引用到csharp unity
- json - 如何从嵌套的json中提取键值对
- unreal-engine4 - UE4:仍然生成对象,即使我将其设置为“不生成”
- scala - 如何将 Free monad 转换为 Free applicatives
- python - 如何将本地保存的图像添加到 python 中的绘图图形?
- javascript - 它作为组合值传递 4,5,6
- haskell - GHC 多包版本警告的严重性
- ssis - 将可变长度记录解析为表列,其中特定列在 SSIS 2016 中是动态的