Quantcast
Viewing all articles
Browse latest Browse all 32

Can't Insert array data into QTableWidget PyQt5

I am making a desktop app for scientific purposes, and I am struggling to find info on the topic.

I have the code that scans the specific folder of excel files and saves its names and paths

sample_directory_2 = []sample_files_2 = []for (dirpath, dirnames, filenames) in walk('./Processed'):    filenames = [f for f in filenames if not f[0] == '.']    sample_files_2.extend(filenames)    breakthe_dir = "Processed"paths_2 = [os.path.abspath(os.path.join(the_dir,filename)) for filename in os.listdir(the_dir) if not filename.startswith('.')]    sample_directory_2.append(sample_files_2)sample_directory_2.append(paths_2)

Further, I have a piece of code, which gets the data from these files

processed_info = []for i in range(len(sample_directory_2[0])):    file_info = []    sample_file_2 = sample_directory_2[0][i]    sample_path_2 = sample_directory_2[1][i]                sample_info_2 = pd.read_excel(ospath(sample_path_2), header = None, sheetname = 3)    sample_info_2 = sample_info_2.iloc[0][0:3]    file_info.append(sample_file_2)    sample_info_2_list = numpy.array(sample_info_2).tolist()     file_info.extend(sample_info_2_list)    processed_info.append(file_info)

It is saved into an array

[['sample1 (02:03:2018 14-38).xlsx', 3892.523626752876, 18.64406779661017, 0.6938147012986077],

['sample2 (02:03:2018 14-38).xlsx', 6135.581250460564, 79.66101694915254, 0.6072608909734578],

['sample3 (02:03:2018 14-38).xlsx', 3461.456815612303, 5.084745762711865, 0.676008795372024],

['sample4 (05:03:2018 07-28).xlsx', 6135.581250460564, 79.66101694915254, 0.6072608909734578]]

How to insert these pieces of data into QTableWidget cells, where each list (for example:['sample1 (02:03:2018 14-38).xlsx', 3892.523626752876, 18.64406779661017, 0.6938147012986077]) is inserted as a new row with 4 columns?

UPD: Found a way to add an item with

for row in range(len(processed_info)):        for column in range(len(processed_info[row])):            self.clickSample_list.setItem(row, column, QTableWidgetItem(processed_info[row][column]))

but, for some reason, it adds only first items of lists: Image may be NSFW.
Clik here to view.
screenshot

How is that possible?


Viewing all articles
Browse latest Browse all 32

Trending Articles