How can I add a widget in a QTableWidget header?
Unsolved
Qt for Python
-
Hi!
I've got a QTableWidget with a lots of comboboxes inside it.
Here is a minimal example.
import sys from PySide6.QtCore import Qt from PySide6.QtWidgets import ( QApplication, QComboBox, QTableWidget, ) app = QApplication(sys.argv) headers = ["Country", "City", "Road"] countries = ["France", "England", "Spain"] cities = ["Paris", "London", "Madrid"] roads = ["Elysées", "Picadily circus", "Prado"] def get_combo(input_l: list[str]) -> QComboBox: combo = QComboBox() for item in input_l: combo.insertItem(10, item) combo.setCurrentText(input_l[0]) return combo def fill_in_table(input_table: QTableWidget, N: int) -> None: for row in range(N): input_table.setCellWidget(row, 0, get_combo(countries)) input_table.setCellWidget(row, 1, get_combo(cities)) input_table.setCellWidget(row, 2, get_combo(roads)) table = QTableWidget() table.setSortingEnabled(True) table.horizontalHeader().setSortIndicator(0, Qt.SortOrder.AscendingOrder) table.setColumnCount(len(headers)) table.setRowCount(10) fill_in_table(table, 10) table.setHorizontalHeaderLabels(headers) table.show() app.exec()
I want to add a filter combobox in a header. A kind of l menu to select "France" rows.
I saw a QTableWidgetItem can be provided to fill-in a header, but I can't include a widget...Is it possible to achieve that?
Thanks for your help!