I’ve created a class called CustomTextEdit that derives from QTextEdit. The derived class is going to be used in a larger project and lets users insert tables through a menu action. The problem I face is that the program does not allow users to drag and resize the table like they can in MS Word. When the user hovers the mouse pointer over a column, the cursor must change to Qt. SplitHCursor and dragging one of the columns must resize it. I also want to detect if the table is in focus so that I can make the program show options to edit the table (like insert above, insert below).
I tried something like this. But it does not work.
def insert_table(self):
dialog = QInputDialog.getText(
self, "Table",
"Enter the number of rows and columns seperated by commas")
cursor = QCursor(Qt.SplitHCursor)
pos = cursor.pos()
details, value = dialog
self.format = QTextTableFormat()
self.format.setColumnWidthConstraints([QTextLength(QTextLength.PercentageLength, 10.0)]*int(details.split(",")[1]))
rows, columns = tuple(details.split(","))
self.cursorPosition = self.editor.textCursor()
self.table = self.cursorPosition.insertTable(int(rows), int(columns))
self.table.setFormat(self.format)
Singing Account is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.