How do multiple "GtkLabel" manage ellipsis?

I need to bind click event and ::hover for each GtkLabel

Are there currently any containers that can do this?

It is not clear how your title relates to the body of the post. Which are you actually asking about?

What layout do you currently have, what functionality is it missing, and what have you tried?

|                                |
+----------+ +----------+ +--------------+
|label-----+ +-label----+ +--l...+-------+
|                                |

The question is still very unclear. You can listen for click and hover events on GtkLabel directly in GTK4; the container should not need to get involved. And those should work just the same on an ellipsized label

The specific layout structure is the same as the previous note. The meaning is clear.

A container manages many tags, and each tag can receive events.

But the container has a finite width, so inevitably there will be labels that extend beyond the bounds of the box.

Like the third label above, half is inside the box and half is outside.

I don’t accept directly hiding excess stuff, it’s unreasonable.

So the correct result is: the third tag uses an ellipsis to indicate that there is content behind it

If this is not clear enough, please refer to <span>: The Content Span element - HTML: HyperText Markup Language | MDN

As an inline element, it supports events, supports css, participates in paragraph management (I only need end-of-line ellipses).

So how does gtk express span?

The meaning is clear.

It is not. You seem to be using custom terminology, of containers having tags or spans, which is at odds with GTK terminology (a container would hold a label, which would hold spans of text with attributes).

But thanks for implying I’m dense. I’ll leave this to someone who is not, then.

You are too sensitive.

If you’ve written html, you know this is pretty basic stuff. So the logic is clear.

In fact, when I was writing that paragraph, I deleted a sentence.

don’t tell me html is different from gtk

I can solve my problem, but I want to know if there is a more perfect solution in gtk.

I wrote a simple container, but it works great

	int x_offset = 0;
		_child = child;

		if ( x_offset >= width )

		int child_width = 0, nat = 0;
		gtk_widget_measure( child, GTK_ORIENTATION_HORIZONTAL, -1, &child_width, &child_width, NULL, NULL );
		int child_height = 0;
		gtk_widget_measure( child, GTK_ORIENTATION_VERTICAL, -1, &child_height, &nat, NULL, NULL );

		if ( x_offset + child_width > width ) {
			child_width = width - x_offset;

		gtk_widget_size_allocate( child, &_GTK_ALLOCATION_INIT( x_offset, 0, child_width, child_height ), baseline );

		x_offset += child_width;


So it should be discussed how to achieve it instead of avoiding it because of different concepts

I’m not ‘avoiding’ anything. I just don’t understand your problem enough to comment further.

1 Like

After watching the GIF, can you understand everything I said now?

My ascii image is exactly the same as my gif image, which is why I insisted on saying “clear”.

This is easy to achieve in a single GtkLabel , gtk does a lot of work. But I need an answer when multiple labels need to be processed.

It doesn’t; that concept does not apply to GTK, although Pango has some support for parsing a subset of HTML.

Set the ellipsize property on the label. Job done.

Have you written containers? Is there anything special about inline elements? Can it only be html exclusive?

In fact gtk is full of concepts of inline elements. But when it comes to label, more APIs are needed for event handling. (or register all events for GtkWidget to forward)
If you want to cross boundaries, you can only divide the label into the smallest unit, that is, each label only stores one character. In this way, all functions can be realized (in fact, only part of the functions can be completed)

“everyone knows”


Can you give me a specific solution? Use that container?

The above two pictures are the result of GtkBox containing multiple GtkLabels

Okay, that’s a different situation than presented in your GIF. You’re going to get a lot better help and more help, if you drop the attitude and explain your full situation when requested. This isn’t a custom service center.

Put the separate strings of text in a single label, set ellipsize to true, use markup to make them clickable, connect to the activate-link signal to override the activation behaviour, and use a GtkEventControllerMotion to respond to hovering.

1 Like

I don’t think I have an arrogant attitude. But since you feel uncomfortable, I’m sorry. :<

Thanks for your answer.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.