Issue
So i have my main code here
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.table_luni_anul_1 = TableWidget(anul_1, "Luni")
self.ani_tab = QTabWidget()
self.anul_1_tab = TabWidget()
self.anul_1_tab.insert_tabs([self.table_luni_anul_1])
self.ani_tab.addTab(self.anul_1_tab, "Anul 1")
self.delete=DeleteWidget()
type here
And the classes DeleteWidget and TableWidget DeleteWidget.py
class DeleteWidget(QPushButton):
def __init__(self,ani):
QPushButton.__init__(self)
self.ani=ani
self.setFixedSize(30, 260)
self.setStyleSheet('QPushButton {font-size: 20px;}')
self.setText('D\nE\nL\nE\nT\nE\n')
self.clicked.connect(self.delete_data) # dont know where to put function that calls when pushbutton is pressed
TableWidget.py
class TableWidget(QTableWidget):
def __init__(self, data, name):
QTableWidget.__init__(self, 12, len(data))
self.name = name
self.data = data
self.setData()
self.setAcceptDrops(True)
self.setDragEnabled(False)
# self.setDragDropMode(QTableWidget.InternalMove) # Objects can only be drag/dropped internally and are moved instead of copied
# self.setDragDropOverwriteMode(False)
for i in range(len(self.data)): self.setColumnWidth(i, 80)
def setData(self):
horizontal_headers = []
vertical_headers = []
for n in self.data:
horizontal_headers.append(n)
self.setHorizontalHeaderLabels(horizontal_headers)
for i in range(8, 20):
vertical_headers.append(f"{i}")
self.setVerticalHeaderLabels(vertical_headers)
I have tried everything but cant get my head to understand how this should work. I want to delete selected cells of the user from the table.Not eliminate rows ,just delete content that is written.
Solution
It could look something like this
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.table_luni_anul_1 = TableWidget(anul_1, "Luni")
self.ani_tab = QTabWidget()
self.anul_1_tab = TabWidget()
self.anul_1_tab.insert_tabs([self.table_luni_anul_1])
self.ani_tab.addTab(self.anul_1_tab, "Anul 1")
self.delete=DeleteWidget()
self.delete.clicked.connect(self.delete_selection)
def delete_selection(self):
for item in self.table_luni_anul_1.selectedItems():
# ... this is were you would clear the items value
item.setText('')
Answered By - Alexander
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.