admin管理员组文章数量:1401673
I want to display MarkDown in a QTextEdit
or a QTextBrowser
as read-only. However, I want to be able to toggle MarkDown checkboxes. But if I set setReadOnly(true);
the checkboxes are not clickable.
I tried various combinations of setTextInteractionFlags(Qt::LinksAccessibleByMouse);
etc. but either the whole text is editable or the checkboxes are not clickable.
Is there a way to achieve this?
I want to display MarkDown in a QTextEdit
or a QTextBrowser
as read-only. However, I want to be able to toggle MarkDown checkboxes. But if I set setReadOnly(true);
the checkboxes are not clickable.
I tried various combinations of setTextInteractionFlags(Qt::LinksAccessibleByMouse);
etc. but either the whole text is editable or the checkboxes are not clickable.
Is there a way to achieve this?
Share Improve this question edited Mar 25 at 2:26 musicamante 48.7k8 gold badges41 silver badges74 bronze badges asked Mar 24 at 13:10 CryptkeeperCryptkeeper 1631 silver badge9 bronze badges 1 |1 Answer
Reset to default 1I found a more or less "hacky" workaround by overriding mouse handlers but without the need to handle the document manipulation itself, by enabling write "just in time":
void ReadOnlyTextEdit::mouseReleaseEvent(QMouseEvent *event)
{
setReadOnly(false);
QTextEdit::mouseReleaseEvent(event);
setReadOnly(true);
}
void ReadOnlyTextEdit::mouseMoveEvent(QMouseEvent *event)
{
setReadOnly(false);
QTextEdit::mouseMoveEvent(event);
setReadOnly(true);
}
So far it seems to work and I have not found any drawbacks yet.
本文标签: cUse QTextEdit or QTextBrowser readonly but keep MarkDown Checkboxes clickableStack Overflow
版权声明:本文标题:c++ - Use QTextEdit or QTextBrowser readonly but keep MarkDown Checkboxes clickable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744250175a2597215.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
readOnly
property is fundamentally the same as callingsetTextInteractionFlags()
with related options, and toggling a checkbox actually changes the contents of the document, therefore you cannot make the document read only and still keep checkboxes interactive. The only way to achieve this is by overriding mouse handlers (press, move and release), get the document'sdocumentLayout()
and callblockWithMarkerAt()
, then eventually work with it based on the mouse event, if the block is valid. – musicamante Commented Mar 24 at 20:55