\n
Example of what I'm trying to build. Clicking the corner box should open a dropdown that has various things
\n\nI already tried to override the selectAll()
functionality to do other actions but I'm unable to replace the entire section with a new custom widget
Code
\nfrom PyQt6.QtWidgets import QTableWidget, QApplication, \\\n QTableWidgetItem, QMainWindow, QWidget, QHBoxLayout\n\nclass CustomWatchlist(QTableWidget):\n def __init__(self):\n super(CustomWatchlist, self).__init__()\n\n self.horizontalHeader().setDefaultSectionSize(100)\n self.setColumnCount(2)\n \n self.header_labels = ['Symbol', 'Mark']\n self.setHorizontalHeaderLabels(self.header_labels)\n \n self.data = {'MSFT': '100.0',\n 'AAPL': '205.5',\n 'QQQ': '350.0'}\n \n for index, symbol in enumerate(self.data):\n row_position = self.rowCount()\n self.insertRow(row_position)\n self.setItem(index, 0, QTableWidgetItem(symbol))\n self.setItem(index, 1, QTableWidgetItem(self.data[symbol]))\n \nif __name__ == '__main__':\n app = QApplication([])\n \n main_window = QMainWindow()\n main_window.setMinimumWidth(200)\n main_window.setMinimumHeight(200)\n \n central_widget = QWidget()\n main_layout = QHBoxLayout()\n central_widget.setLayout(main_layout)\n main_window.setCentralWidget(central_widget)\n \n table = CustomWatchlist()\n \n main_layout.addWidget(table)\n \n main_window.show()\n app.exec()\n
\n","author":{"@type":"Person","name":"Ryanc88"},"upvoteCount":1,"answerCount":0,"acceptedAnswer":null}}Reputation: 192
I'm trying to build a custom watchlist widget using QTableWidget
. By default, in the top left corner, if you press the empty box, it will select all items in the table. I want to replace this empty box with my own custom widget to add a QComboBox
dropdown. Is this even possible? If so, how can I build this?
Example of what I'm trying to build. Clicking the corner box should open a dropdown that has various things
I already tried to override the selectAll()
functionality to do other actions but I'm unable to replace the entire section with a new custom widget
Code
from PyQt6.QtWidgets import QTableWidget, QApplication, \
QTableWidgetItem, QMainWindow, QWidget, QHBoxLayout
class CustomWatchlist(QTableWidget):
def __init__(self):
super(CustomWatchlist, self).__init__()
self.horizontalHeader().setDefaultSectionSize(100)
self.setColumnCount(2)
self.header_labels = ['Symbol', 'Mark']
self.setHorizontalHeaderLabels(self.header_labels)
self.data = {'MSFT': '100.0',
'AAPL': '205.5',
'QQQ': '350.0'}
for index, symbol in enumerate(self.data):
row_position = self.rowCount()
self.insertRow(row_position)
self.setItem(index, 0, QTableWidgetItem(symbol))
self.setItem(index, 1, QTableWidgetItem(self.data[symbol]))
if __name__ == '__main__':
app = QApplication([])
main_window = QMainWindow()
main_window.setMinimumWidth(200)
main_window.setMinimumHeight(200)
central_widget = QWidget()
main_layout = QHBoxLayout()
central_widget.setLayout(main_layout)
main_window.setCentralWidget(central_widget)
table = CustomWatchlist()
main_layout.addWidget(table)
main_window.show()
app.exec()
Upvotes: 1
Views: 24