Reputation: 1
How can I align this "PushButton" to the right of the "Options" column and reduce the size of this specific column, without changing the other columns.
I am using Python and QtDesign with PyQt6.
Below is the image: MainWindow With QTableWidget
Below is the code:
from PyQt6 import QtWidgets, QtGui, uic, QtCore
def show_data(self, data, button_column_index=None):
table = self.ui.tableWidget
row_count = len(data)
table.setRowCount(row_count)
if data:
for row, row_data in enumerate(data):
row_data = list(row_data)
row_data.append("")
action_edit = QtGui.QAction("Edit", self)
action_delete = QtGui.QAction("Delete", self)
action_edit.triggered.connect(lambda: self.action_edit_triggered(table))
action_delete.triggered.connect(lambda: self.action_delete_triggered(table))
menu = QtWidgets.QMenu()
menu.addActions([action_edit, action_delete])
option_btn = QtWidgets.QPushButton(self)
option_btn.setIcon(QtGui.QIcon('./user_interface/icons/menu.svg'))
option_btn.setFixedWidth(24)
option_btn.setFixedHeight(24)
option_btn.setStyleSheet("QPushButton{background-color:#f2f2f2; color:#f2f2f2; text-align:center; border-radius:12px;} QPushButton:hover{background-color:#d9d9d9;}")
option_btn.setMenu(menu)
for column, item in enumerate(row_data):
if column == button_column_index:
table.setCellWidget(row, column, option_btn)
else:
item_obj = QtWidgets.QTableWidgetItem(str(item))
table.setItem(row, column, item_obj)
Upvotes: 0
Views: 20