Hello guys, I have been trying to declare a variable globally (var below) when I click in an item of a list (calling fn1), so I can have it identified when I click in another list (calling fn2).
I tried to pass the argument but it doesnt work for me as the event “clicked” asks some sytax that I dont know how to do it, or I am making some mistake.
Anyone has a possible solution for that?
Thanks in advance!
class HairTubeTool(QtWidgets.QWidget):
"""
Create a default tool window.
"""
global var
def __init__(self, parent = None):
"""
Initialize class
"""
super(HairTubeTool, self).__init__(parent = parent)
self.setWindowFlags(QtCore.Qt.Window)
self.widgetPath = ("")
self.widget = QtUiTools.QUiLoader().load(self.widgetPath)
self.widget.setParent(self)
# initial window size
self.resize(400, 720)
# >>>>> LISTS
# a_list
self.a_list = self.widget.findChild(QtWidgets.QListView, 'a_list')
self.list1 = QtGui.QStandardItemModel()
self.a_list.setModel(self.list1)
self.a_list.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
self.a_list.clicked[QtCore.QModelIndex].connect(self.fn1)
# b_list
self.b_list = self.widget.findChild(QtWidgets.QListView, 'b_list')
self.list2 = QtGui.QStandardItemModel()
self.b_list.setModel(self.list2)
self.b_list.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
self.b_list.clicked[QtCore.QModelIndex].connect(self.fn2)
def fn1(self, index):
var = self.list1.itemFromIndex(index)
def fn2(self, index):
print (var)