Solved Make a line break in a layout or container
-
@EL-jos
Oh, so its not URLS at all.
Do you need rich text stuff like bold, and images too ?
or JUST text ? -
@mrjj said in Make a line break in a layout or container:
Oh, so its not URLS at all.
Do you need rich text stuff like bold, and images too ?
or JUST text ?Yes, I want the rich text and images because I have to create an emoji system (smile)
-
@EL-jos
Ok, so QTextEdit could be used as it support all. including word wrap at random positions.
But QLabel also do when there are spaces in the text as there should be with chat text. -
@mrjj said in Make a line break in a layout or container:
Ok, so QTextEdit could be used as it support all. including word wrap at random positions.
But QLabel also do when there are spaces in the text as there should be with chat text.Thank you for the answer but how do I get the images?
Note: so insert the images for example in the text during a conversation as shown in the image above?
-
Hi,
Since it's going to be a chat like visualisation, you might want to consider using Qt's model view framework. Otherwise you might going to instantiate lots of widgets and finally hit a performance hit. A custom QStyledItemDelegate will likely give you the best result.
-
@EL-jos
Hi
You can insert images via the supported subset of html.
Oh, SGaist beat me to it. It will fast become slow, however if u have long
conversations. -
@SGaist said in Make a line break in a layout or container:
Since it's going to be a chat like visualisation, you might want to consider using Qt's model view framework. Otherwise you might going to instantiate lots of widgets and finally hit a performance hit. A custom QStyledItemDelegate will likely give you the best result.
Hi sorry I don't know how it works the QStyledItemDelegate
-
@mrjj said in Make a line break in a layout or container:
Hi
You can insert images via the supported subset of html.
Oh, SGaist beat me to it. It will fast become slow, however if u have long
conversations.Thank you for the answer,
can you give me an example so I can do a simple simulation? -
Are you already familiar with Qt's model view programming ?
-
@mrjj said in Make a line break in a layout or container:
You mean test of Qlabels ?
no the test with a QTextEdit and an HTML subset to display an image as in the conversation given as an example above
-
@SGaist said in Make a line break in a layout or container:
Are you already familiar with Qt's model view programming ?
not just the basics too much
-
Then you should also take a look at @VRonin and @kshegunov's chat example project.
[VRonin edited to proper attribute credit]
-
@SGaist said in Make a line break in a layout or container:
Then you should also take a look at @VRonin's chat example project.
All right, I'll take a look later, since @mrjj is offering me a rather simple solution.
-
@EL-jos
sorry but its not a good solution for a chat app :)
Delegate would be much better. I was too quick to suggest QLabel/TextEdit.
It will not scroll nice, very fast.Anyway, you can have images in Qlabel
label->setText("<html><head/><body><p>thi is the text that says heeelo hello</p><p><img src=\":/test.jpg\"/>and more hello</p></body></html>");
Notice the syntax for the image
":/test.jpg"
its in a resource file.There is an editor if you right click the QLabel on the form.
-
Okay, thank you very much for your example.
but why do you say a Delegate is much better?
what are the advantages of the Delegate?
and what are the disadvantages of rich text with HTML image? -
@EL-jos
A Delegate is a custem draw for a ListView ( or any view)
So instead of drawing the normal cell, you make a small class where you use
QPainter to draw the cell how you want it.
Its much faster than having a tons of QLabels in a layout as
Views has been optimized for having many items.so the clear benefit is that it works very fast and it can draw however you like.
(well you have to program that part)Using html , you would have to construct the right html to have it look how u want.
Some thing be much harder. Like the clock/time in the whatapps sample.With Delegate you can simply paint it there.
However, learning to use Views and Delegates will take some practice.
-
@mrjj said in Make a line break in a layout or container:
A Delegate is a custem draw for a ListView ( or any view)
So instead of drawing the normal cell, you make a small class where you use
QPainter to draw the cell how you want it.
Its much faster than having a tons of QLabels in a layout as
Views has been optimized for having many items.
so the clear benefit is that it works very fast and it can draw however you like.
(well you have to program that part)
Using html , you would have to construct the right html to have it look how u want.
Some thing be much harder. Like the clock/time in the whatapps sample.
With Delegate you can simply paint it there.
However, learning to use Views and Delegates will take some practice.Thank you very much for the answer.
but can you give me a training link on the view and the delegate? -
Did you took a look at the documentation I linked to earlier ? It does explain everything with examples.
There's the model view tutorial and the Item Views examples.
-
@SGaist said in Make a line break in a layout or container:
Did you took a look at the documentation I linked to earlier ? It does explain everything with examples.
Yeah, but it's a little complicated for me.
-
@EL-jos
Hi
maybe this is easier to follow ?
https://www.bogotobogo.com/Qt/Qt5_QListView_QStringListModel_ModelView_MVC.phpTry to follow the steps and build the same.
It looks more complicated than it is.