Currently selected table in QTextEdit?
-
I'm trying to figure out how I can get information
about the currently selected table, row and/or cell
in a QTextEdit.
Is there such a capability?@clarify said in Currently selected table in QTextEdit?:
row and/or cell in a QTextEdit
That a
QTextEdit
has cells and rows/cols is new to me :)You are sure that you don't have a
QTableView
(or -Widget
) or something else model-based?!Edit:
Are you talking about HTML tables inQTextEdit
?
AFAIKQTextEdit::setHtml
is one-way. You set CSS/HTML once and you see the result. You don't get any callbacks or something else than theQTextEdit
signals and events back from it. -
@clarify said in Currently selected table in QTextEdit?:
row and/or cell in a QTextEdit
That a
QTextEdit
has cells and rows/cols is new to me :)You are sure that you don't have a
QTableView
(or -Widget
) or something else model-based?!Edit:
Are you talking about HTML tables inQTextEdit
?
AFAIKQTextEdit::setHtml
is one-way. You set CSS/HTML once and you see the result. You don't get any callbacks or something else than theQTextEdit
signals and events back from it.@Pl45m4 said in Currently selected table in QTextEdit?:
Are you talking about HTML tables in QTextEdit?
Yes. You can try this yourself:
textedit->setHtml("<html><body><table border=1><tr><td>1<td width=100>2<td>3<tr><td>4<th>5<th>6</table>");
The QTextEdit is smart enough to parse the HTML for the table and display it nicely. However as yet I don't see how I can let the user edit the table's structure e.g. add rows, delete column etc.
Does anyone know if that is coming in Qt 6? (My Linux distro is stuck at Qt 5).
AFAIK QTextEdit::setHtml is one-way.
You can read HTML out of the QTextEdit with a call to toHtml. And it's an editor, so you can edit anything in there. It's just the table structure that I can't see a way to alter.
-
@Pl45m4 said in Currently selected table in QTextEdit?:
Are you talking about HTML tables in QTextEdit?
Yes. You can try this yourself:
textedit->setHtml("<html><body><table border=1><tr><td>1<td width=100>2<td>3<tr><td>4<th>5<th>6</table>");
The QTextEdit is smart enough to parse the HTML for the table and display it nicely. However as yet I don't see how I can let the user edit the table's structure e.g. add rows, delete column etc.
Does anyone know if that is coming in Qt 6? (My Linux distro is stuck at Qt 5).
AFAIK QTextEdit::setHtml is one-way.
You can read HTML out of the QTextEdit with a call to toHtml. And it's an editor, so you can edit anything in there. It's just the table structure that I can't see a way to alter.
@clarify
Have a look at QTextTableThe table currently being edited by the cursor is found with QTextCursor::currentTable(). This allows its format or dimensions to be changed after it has been inserted into a document.
A table's size can be changed with resize(), or by using insertRows(), insertColumns(), removeRows(), or removeColumns(). Use cellAt() to retrieve table cells.
-
@Pl45m4 said in Currently selected table in QTextEdit?:
Are you talking about HTML tables in QTextEdit?
Yes. You can try this yourself:
textedit->setHtml("<html><body><table border=1><tr><td>1<td width=100>2<td>3<tr><td>4<th>5<th>6</table>");
The QTextEdit is smart enough to parse the HTML for the table and display it nicely. However as yet I don't see how I can let the user edit the table's structure e.g. add rows, delete column etc.
Does anyone know if that is coming in Qt 6? (My Linux distro is stuck at Qt 5).
AFAIK QTextEdit::setHtml is one-way.
You can read HTML out of the QTextEdit with a call to toHtml. And it's an editor, so you can edit anything in there. It's just the table structure that I can't see a way to alter.
@clarify said in Currently selected table in QTextEdit?:
You can read HTML out of the QTextEdit with a call to toHtml. And it's an editor, so you can edit anything in there. It's just the table structure that I can't see a way to alter.
I know that you can change the data in HTML tables but you dont have the functionality that a e.g.
QTableView
orQTableWidget
provides. With hover events, interactive header, data model etc..Look at @mpergand 's answer.
QTextTable
(a class I didnt know of) was added in Qt6. -
@clarify said in Currently selected table in QTextEdit?:
You can read HTML out of the QTextEdit with a call to toHtml. And it's an editor, so you can edit anything in there. It's just the table structure that I can't see a way to alter.
I know that you can change the data in HTML tables but you dont have the functionality that a e.g.
QTableView
orQTableWidget
provides. With hover events, interactive header, data model etc..Look at @mpergand 's answer.
QTextTable
(a class I didnt know of) was added in Qt6. -
@Pl45m4 said in Currently selected table in QTextEdit?:
QTextTable (a class I didnt know of) was added in Qt6.
Exists since Qt4 !