Currently selected table in QTextEdit?
-
wrote on 12 May 2023, 21:36 last edited by
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? -
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?wrote on 12 May 2023, 21:49 last edited by Pl45m4 5 Dec 2023, 21:59@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.wrote on 12 May 2023, 22:10 last edited by clarify 5 Dec 2023, 22:17@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.
wrote on 12 May 2023, 22:37 last edited by mpergand 5 Dec 2023, 22:37@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.
wrote on 12 May 2023, 22:44 last edited by Pl45m4 5 Dec 2023, 22:44@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.wrote on 12 May 2023, 22:59 last edited by@Pl45m4 said in Currently selected table in QTextEdit?:
QTextTable (a class I didnt know of) was added in Qt6.
Exists since Qt4 !
-
@Pl45m4 said in Currently selected table in QTextEdit?:
QTextTable (a class I didnt know of) was added in Qt6.
Exists since Qt4 !
wrote on 13 May 2023, 12:19 last edited by@mpergand said in Currently selected table in QTextEdit?:
Exists since Qt4 !
Mh ok. There were only Qt6 Releases listed in the documentation, not even 5.15.
Still never heard of it and it doesnt seem to be used very often.
6/7