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

How to resize contents in Qlistwidget



  • hi,,,
    im doing chat application,,if i resize application messages are not showing and showing only when i did full screen please help me 0_1552395584987_1552395550007.JPEG

    how to resize contents(QLIstWidgetItem) in QListwidget

    thanks in advance0_1552395592412_1552395549936.JPEG



  • reimplement resizeEvent() for the child widget contained in the scroll area.



  • i override resize event still messages are not resizing



  • @Bharth said in How to resize contents in Qlistwidget:

    i override resize event still messages are not resizing

    well, what is the substance of your resizeEvent() handler?

    anything like:

    this->resize(this->parent().size())
    

  • Lifetime Qt Champion

    Hi,

    Can you show the code you are currently using ?



  • this is code im adding listwidgetiem (chatpage.cpp)

           pListWidgetItem = new QListWidgetItem(ui->list_chat);
            ui->list_chat->addItem(pListWidgetItem);
            pChatCell = new ChatCell(this,pMessage,textmessage,strQuote,strDateTime,bFilter);
            pListWidgetItem->setSizeHint(pChatCell->sizeHint());
            ui->list_chat->setItemWidget(pListWidgetItem, pChatCell);
    

    void ChatPage::resizeEvent(QResizeEvent *event)
    {
    QSize size = this->size();
    if(pChatCell!=nullptr)
    {
    pChatCell->setMinimumWidth(size.width());
    pChatCell->setMinimumHeight(size.height());
    pChatCell->setMaximumWidth(size.width());
    pChatCell->setMaximumHeight(size.height());
    MainSubPage::resizeEvent(event);
    pListWidgetItem->sizeHint();
    }

    }

    here ChatCell is another widget



  • @Kent-Dorfman
    where i have to add this chatpage(Qlistwidget) or chatcell(QlistwidgetItem)



  • @Bharth said in How to resize contents in Qlistwidget:

    void ChatPage::resizeEvent(QResizeEvent *event)
    {
    QSize size = this->size();
    if(pChatCell!=nullptr)
    {
    pChatCell->setMinimumWidth(size.width());
    pChatCell->setMinimumHeight(size.height());
    pChatCell->setMaximumWidth(size.width());
    pChatCell->setMaximumHeight(size.height());
    MainSubPage::resizeEvent(event);
    pListWidgetItem->sizeHint();
    }
    }

    Why are you changing the size constraints within the resize event? That's what size policies are for. Also, what happens if you try to setMinimumSize to a value greater than the current maximum size, or conversely you try to setMaximumSize less than the current minimum?

    All I was suggesting is that you override the child resizeEvent to consider the available space that the parent has given it. I believe a resize in the parent will recursively call the resize for all of its children in a breadth first search pattern.


  • Lifetime Qt Champion

    Why are you using a QScrollArea at all ?

    QListView/Widget already handles that part if its content becomes bigger than the viewport.


Log in to reply