Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget should have 'display-only' mode #14

Open
mjakeman opened this issue Jun 8, 2022 · 1 comment
Open

Widget should have 'display-only' mode #14

mjakeman opened this issue Jun 8, 2022 · 1 comment
Milestone

Comments

@mjakeman
Copy link
Owner

mjakeman commented Jun 8, 2022

Add a distinction between editable and non-editable text widgets

When used in display-only mode, see if we can disable or remove the editor logic to improve performance somewhat.

We'll need this for porting Extension Manager to 0.2.

@mjakeman mjakeman added this to the 0.2 milestone Jun 8, 2022
@ferdnyc
Copy link

ferdnyc commented Sep 1, 2024

👍

One of the ways I think this widget would be most useful, in terms of the greater Gtk4 ecosystem, is if it worked a simple-to-use, bare-bones display widget for rich-text rendered from various formats — say, as a starting point (and because it's the simplest of the markup formats), MarkDown.

Since Qt 5.14 their basic QTextEdit (as well as QTextBrowser and QTextDocument) has supported rendering of MarkDown source right in the widget, in addition to the (bare-bones Qt subset of) HTML source it already supported.

The interface is as easy as can be:

MarkdownDialog::MarkdownDialog(QWidget *parent)
    : QDialog(parent)
{
    std::string mdContent{R"md(
# Markdown display demo

QTextEdit can display editable or read-only rich text from MarkDown source
with simple API calls to render MarkDown *into* the widget, or to retrieve
MarkDown *out* of the widget.

It supports GitHub Flavored MarkDown by default (except that, for some
reason, it parses underscores as _underline_ markup), including:


|Feature           |Notes              |
|------------------|-------------------|
|Tables            | (as seen here)    |
|Ordered Lists     | [See below](#OL)  |
|Unordered lists   | [See below](#UL)  |
|Checklists        | [See below](#CL)  |
|And much more     |                   |

## OL

1. First item
1. Second item
   1. Nested

## UL

* Bullet 1
* Bullet 2
  * Nested

## CL

- [ ] Checkbox 1
- [ ] Checkbox 2
- [x] Checked box

)md"};
    auto* mdText = new QTextEdit(this);
    this->layout()->addWidget(mdText);
    mdText->setMarkdown(QString::fromStdString(mdContent));
    mdText->setReadOnly(true);
    mdText->setWordWrapMode(QTextOption::WordWrap);
    mdText->show();
}

Write a barebones main.cpp that just creates the dialog and ->show()s it, compile and run, and...

image

Similarly, there's a QTextEdit::setHTML() for taking advantage of that barebones HTML subset I mentioned.

And that's in a standard QtWidgets component, built right into the framework — the equivalent of GtkTextView. It's insane that, even in 2024, Gtk4 doesn't provide rich-text functionality that's even close to that seamless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants