Hope you are fine.
I populated a table with images and it behaves like I want for the most part, except when I connect the cell to a cellClicked signal.
Lets say I have this function
def print_cell (column,row):
print(column,row)
...
table.cellClicked.connect(print_cell)
This works as intended, prints a (column, row) pair when the cell is clicked, but i need a bit more than this. My intended function needs more than the column and row pair.
I need something like this:
def print_cell(column, row, max_column_count)
print(row*max_column_count + column) #I need to convert to array to load files.
I dont understand how this can be done as cellClicked only gives me column and row. I have tried more than a few things but nothing seems to work, I would like your clean slate suggestions as I might have understood wrong.
Edit: providing a bit more of minimal code.
# import
# The imports we are using are custom made except for os, sys and math, but they include everything we need. I will use the name custom_module when instancing this classes, but they are basic a shortcut to PySide2 stuff.
def count_files(*args):
pass
#This counts the number of files given name prefix or extension inside a defined folder. It returns a unsigned integer with the total.
def print_cell(row,column):
print(row,column) #this is the function I want to improve.
class PyDialog(custom_module.QDialog, custom_module.QMainWindow):
def __init__(self, path, parent=None):
super(PyDialog, self).__init__(parent)
ext = '.png'
path = 'files'
prefix = 'icon'
file_count = count_files(path,ext)
max_column_count = 4 #This is hardcoded at the moment as this number will depend of other factors.
row_count = math.ceil(float(file_count)/float(max_column_count))
self.window=custom_module.dotui.load_ui(path, self)
table = self.window.img_table
table.setColumnCount(max_column_count)
table.setRowCount(row_count)
for index in range(file_count):
column, row = divmod(index,max_column_count)
icon_label = custom_module.QLabel()
icon_pixmap =custom_module.QPixmap(path+prefix+str(index)+ext)
icon_label.setPixmap(icon_pixmap)
table.setCellWidget(column,row,icon_label)
table.cellClicked.connect(print_cell)
self.window.show()
if __name__ == '__main__':
dialog = PyDialog('path')
A couple of further comments:
Yes, for now the external functions are not part of a class, as pointed out in the comments.
I stripped the code from a lot of functionalities regarding the look of the table, but this might be enough to diagnostic the problem.
Thank you very much.
question from:
https://stackoverflow.com/questions/65899267/how-to-pass-more-arguments-to-a-signal-in-pyside2