here is an example to do it:
int listwidth = 0;
for (int i = 0; i < count() - 1; i++)
{
listwidth = qMax(itemText(i).length(), itemText(i+1).length());
}
listwidth = qMax(sizeHint().width(), listwidth);
QRect availRect
= desktop
->availableGeometry
(this
->parentWidget
());
int maxWidth
= (availRect.
right())-(this
->mapToGlobal
(QPoint(0,
0)).
x())-10;
listwidth = qMin(maxWidth, listwidth);
pView->setMinimumWidth(listwidth );
int listwidth = 0;
QListView* pView = (QListView*)view();
for (int i = 0; i < count() - 1; i++)
{
listwidth = qMax(itemText(i).length(), itemText(i+1).length());
}
listwidth = qMax(sizeHint().width(), listwidth);
QDesktopWidget* desktop = QApplication::desktop();
QRect availRect = desktop->availableGeometry(this->parentWidget());
int maxWidth = (availRect.right())-(this->mapToGlobal(QPoint(0, 0)).x())-10;
listwidth = qMin(maxWidth, listwidth);
pView->setMinimumWidth(listwidth );
To copy to clipboard, switch view to plain text mode
here, u get the view from combobox, find the maximum length of all the items and maximum width according to the parent of combobox..compare it and set the minimum width of the view
Bookmarks