GTK4 Question: textview, label -- displaying clickable "links" [beginner]

Hi,

I’m asking for guidance :slight_smile:

I’d like to display lots of lines as search results,
each being a local link to local files…
(I use Python)


Q1.

Displaying these lines should be done “in” a textview textbuffer , is this right?

1/a

But displaying links takes lots of tags with positions start and end,
and tag definitions… using " create_tag"… like create_tag

(I haven’t tried this yet)

1/b

or can we go by “insert_markup” ?
like: https://docs.gtk.org/gtk4//method.TextBuffer.insert_markup.html

I’m adding the lines one by one anyhow, using “insert”…
so this doesn’t look so bad…
but I’m not sure…

EDIT(4) PLUS :
Pango Markup doesn’t seem to have “<a href”…


Q2.

Or one can use a label.. or more…
but I read that more than just a few paragraphs can slow down the whole application

so, this is ruled out, too… – right?


Q3.

I could imagine using one uniform tag only, and some kind of “open what’s between the tags” function…

If I know which direction to go, I’ll be already helped :slight_smile:

I just don’t want to spend more time without knowing it…

Thank you in advance,

Peter


PS:

Is it okay to ask this kind of questions here?

It really depends on your use case. Say for example, you are building something like an internet search engine and you want to display the results. I’d personally go with a “SearchResult” button widget that displays the title and description of a result and when clicked opens it in a browser. Then I’d use a recycler view like GtkListView to display them (see A primer on GtkListView – GTK Development Blog). I don’t think a big TextView or Label would be appropriate for this case.

Q1.

See gtk4-demo’s Hypertext demo on how to create and handle link tags.

Q2.

You can give it a try with the maximum input you think your app will handle and see how it works out.

Q3.

Not sure what you mean exactly with that, like a button that shows the links in a different view/dialog?

Is it okay to ask this kind of questions here?

Yes

Thank you for your advice!

Also for your sophisticated first outline! :slight_smile:

In the meantime I realized that listbox is the thing! :slight_smile:

So, seeing that you’re suggesting that primer on listview felt like great news!

listview is not the exact same thing as listbox, right?
I read it and will read it later, too :slight_smile:

Either way, a listbox and rows… is the way to go for me…

I found this great example: (at Layout Containers — PyGObject )

This one really looks promising – perfect!


in Q3,
What I meant by that vague vision was a javascript-like approach – instinctive :slight_smile:


But listbox and rows are really perfect…
I’m making GTK4 UI for an old and cool app and it also uses something like a listbox… not a textview-like thing…

So, thanks really!

Peter

No problem!

listview is not the exact same thing as listbox, right?

Since you mentioned that the list of items can be big, I’d suggested looking into ListView sooner than later.
Read this for a deep dive into the differences and limitations Scalable lists in GTK 4 – GTK Development Blog, but TLDR, ListView is a recycler view; it will create up to 200 rows and re-use them as you scroll, which has many benefits on performance and resource usage.
The downside is that they are a bit more complex and limiting than a ListBox but you can always look at real-world examples in other projects, if the pygobject docs don’t cover it (Code search results · GitHub)

Thank you!

This also means that advantages come after 200 rows, right?

I’ll experiment…
I need to know it anyway :slight_smile:

EDIT:
correction (from the aforementioned Scalable Lists in GTK4 page):

“As a rule of thumb, GtkListBox can handle 1 000 items well, while GtkTreeView works fine for 100 000.”