vnote/src/widgets/combobox.cpp
Le Tan 774930c950
fix combobox style on macOS (#1638)
* fix combobox style on macOS

* fix SingleInstanceGuard on *nix

* fix style on macos

* fix demo
2021-01-02 09:55:46 +08:00

28 lines
566 B
C++

#include "combobox.h"
#include <QAbstractItemModel>
#include <QAbstractItemView>
using namespace vnotex;
ComboBox::ComboBox(QWidget *p_parent)
: QComboBox(p_parent)
{
}
void ComboBox::showPopup()
{
QComboBox::showPopup();
#if defined(Q_OS_MACOS) || defined(Q_OS_LINUX)
auto vw = view();
if (count() > 0) {
int cnt = qMin(count(), maxVisibleItems());
int height = 20 + cnt * vw->visualRect(vw->model()->index(0, 0)).height();
if (height > vw->height()) {
vw->setMinimumHeight(height);
}
}
#endif
}