[Interest] Item / Views: QLabel delegate

Laszlo Papp lpapp at kde.org
Mon Dec 4 16:54:31 CET 2023


Thanks, Tony and Volker. This was very helpful!

I copied Tony's code, and I can see the html appearing. I have some
follow-up questions if you do not mind?

1. I cannot see word wrapping, so potentially long lines are still taking
up one line. And if really long, the messages is not even visible
completely. Would it be possible to have word wrapping so that the long
lines are broken down into multiple rows? Similarly how the word wrapping
property works for QLabels.

2. I can see an html <a href..> element appearing, but I am not sure what
the best way would be to make that clickable like on QLabel.

3. I can see that with the delegate, the decoration role is overridden. Is
there a way to preserve that or would I need to manage all roles now in the
delegate?

For reference, this is what I am trying to achieve for 1-2:

+ QLabel* label = new QLabel(this);
+ label->setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Praesent tempus, nisl accumsan facilisis iaculis, metus erat rutrum tellus,
in tempor arcu urna at neque. Nulla placerat consectetur nulla, in
elementum lorem gravida et. Maecenas non vestibulum urna, malesuada
eleifend felis. Pellentesque varius ut sem a aliquet. Sed a nunc ipsum.
Nunc lobortis et neque id pellentesque. Fusce ac placerat nulla. Aenean
pulvinar magna et est commodo laoreet. Sed et accumsan lorem. In hac
habitasse platea dictumst. Pellentesque ultrices, purus eu blandit
malesuada, arcu elit posuere lectus, vitae placerat magna diam et urna.
Praesent rhoncus imperdiet dictum. Pellentesque mattis tempus ipsum, eu
dignissim mauris tempus in. Proin orci nibh, lacinia nec euismod quis,
ornare sed velit. Maecenas cursus libero tellus.<br><a href=\"
http://example.com/\"><span style=\"color:orange;\">Click
Here!</span></a>");
+ label->setWordWrap(true);
+ label->setTextFormat(Qt::RichText);
+ label->setTextInteractionFlags(Qt::TextBrowserInteraction);
+ label->setOpenExternalLinks(true);
+ layout->addWidget(label);

Thank you in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231204/9347b1d4/attachment.htm>


More information about the Interest mailing list