How to resize contents in Qlistwidget
-
reimplement resizeEvent() for the child widget contained in the scroll area.
-
@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())
-
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.
-
Why are you using a QScrollArea at all ?
QListView/Widget already handles that part if its content becomes bigger than the viewport.