Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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.
    捕获.PNG



  • @Wgxzzzzzzc
    Using a QTextEdit --- 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 via QStyledItemDelegate, 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 sure QStyledItemDelegate can draw a picture just as it draws other widgety stuff.


  • Lifetime Qt Champion

    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:捕获.PNG
    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 a QTextEdit --- 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 via QStyledItemDelegate, 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 sure QStyledItemDelegate 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.


Log in to reply