In Firefox/Chrome/InternetExplorer/Safari/Opera pop-ups from the combobox expand as the content, see Firefox picture:
QComboBox
pop-up does not expand the content. Pop-ups are limited by the size of QComboBox
, see QWebView picture:
So I implemented the QComboBox::showPopup:
void newQComboBox::showPopup() {
int width = this->width();
this->view()->setTextElideMode( Qt::ElideNone );
const int iconSize = this->iconSize().width();
const QFontMetrics fontMetrics = this->fontMetrics();
const int j = this->count();
for( int i=0; i < j; ++i ) {
const int textWidth = fontMetrics.width( this->itemText(i) + "WWW" );
if (this->itemIcon(i).isNull()) {
width = qMax(width, textWidth);
} else {
width = qMax(width, textWidth + iconSize);
}
}
QStyleOptionComboBox opt;
this->initStyleOption(&opt);
QSize size(width, 0);
size = this->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, size, this);
this->view()->setFixedWidth( width );
QComboBox::showPopup();
}
Is there any way to modify (reimplement) the QComboBox::showPopup
of QWebViews
(QtWebkit)?
Qt-BUG (suggestion): https://bugreports.qt.io/browse/QTBUG-35771
I solved using
QProxyStyle
class, example:how to use:
You must apply in
QApplication
(usually filemain.cpp
):@peppe thanks to your comment I got the solution
Please try to make use of the setMinimumWidth function and pass the max width you have calculated. it should work ui.comboBox->view()->setMinimumWidth(width); for more detail please go through https://qt-project.org/forums/viewthread/26388 link