Solved How can i adjust QListWidgetItem's size according to contents?
-
I want finish a work that use QTextEdit to make news bubble and then i use setItemWidget(QListWidgetItem *item, QWidget *widge). I want adjust my QListWidgetItem accoding to content, therefor i use setSizeHint(QTextEdit) but i found that every item's width is similiar.
what effect i want is shown in picture.
-
@Wgxzzzzzzc
Using aQTextEdit
--- or other widget --- for each message leaves the list full of (editable) widgets, over time there might be a hundred widgets. This is "expensive". @SGaist is reminding you that the normal way of handling lists/tables of items is viaQStyledItemDelegate
, which can draw the item to look like a widget but does not consume any resources like an actual widget does.What picture are you wanting to send which demands a
QTextEdit
? I'm sureQStyledItemDelegate
can draw a picture just as it draws other widgety stuff. -
Hi,
How many of these News bubbles are you going to create ?
Depending on that, you should rather move to QStyledItemDelegate.
-
@SGaist sorry, The message bubble is more appropriate than news bubble. this is chat room program and message bubble is a box loading user's message.
Maybe this picture is clearer:
the reason of using QTextEdit is that i want send picture. but now problem is that i can't change QTextEdit's width or height according to its content. -
@Wgxzzzzzzc
Using aQTextEdit
--- or other widget --- for each message leaves the list full of (editable) widgets, over time there might be a hundred widgets. This is "expensive". @SGaist is reminding you that the normal way of handling lists/tables of items is viaQStyledItemDelegate
, which can draw the item to look like a widget but does not consume any resources like an actual widget does.What picture are you wanting to send which demands a
QTextEdit
? I'm sureQStyledItemDelegate
can draw a picture just as it draws other widgety stuff. -
@JonB Ok, I know your meaning and i found out where the problem is. thank your reminder.