0

In the attached image (from HexChat), the wrapped message never goes to the same level as [21:44:03] -Global-, anyone have any idea how I can implement this in my GUI program? Preferably with PyQt5 but just a general idea on how to implement it would also be great.

enter image description here

One thing I have thought of is creating a whole new widget of two widgets: a QLabel for the name and another QLabel with setWordWrap(True) for the message, and adding it to a layout or to a QListView every time a new message appears:

# Each box is a new widget
 ___________________________________________
| name_widget_1|text_wrapped_message_widget |
|              |text_wrapped_message_widget |
|              |text_wrapped_message_widget |
|              |text_wrapped_message_widget |
 -------------------------------------------
 ___________________________________________
| name_widget_2|text_wrapped_message_widget |
|              |text_wrapped_message_widget |
|              |text_wrapped_message_widget |
 -------------------------------------------

, but that will probably be memory heavy? Or not? Maybe that's how it's typically done?

オパラ
  • 317
  • 2
  • 10
  • I doubt that HexChat would use "labels", it most certainly is a basic scroll area with a fast text engine. If you're going to display *a lot* of messages (and no widgets), consider using QTextEdit with the proper viewport margin, alternatively you can obviously use a basic QGridLayout. – musicamante Feb 17 '22 at 13:58
  • Thank you for the reply, @musicamante . What's a "fast text engine"? – オパラ Feb 17 '22 at 14:18
  • Widgets that display formatted text use a text engine in order to provide correct placement of elements, colors, etc. similarly to what a web browser *engine* does. Text areas that can potentially have thousands of line use optimized engines that provide simple formatting elements to improve performance and memory usage. That's the case of QPlainTextEdit, as opposite to QTextEdit. – musicamante Feb 17 '22 at 14:32
  • You could use a flat QTreeView with [an html item-delegate](https://stackoverflow.com/q/1956542/984421) and a custom model. – ekhumoro Feb 17 '22 at 19:57

0 Answers0