#include "customcombobox.h" #include #include #include #include CustomComboBox::CustomComboBox(QWidget *parent) : QComboBox(parent) { setView(new QListView()); if (nullptr != view() && nullptr != view()->window()) { view()->window()->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint); view()->window()->setAttribute(Qt::WA_TranslucentBackground); QGraphicsDropShadowEffect *pShadowEffect = new QGraphicsDropShadowEffect(this); pShadowEffect->setBlurRadius(LISTVIEW_MARGIN); // 模糊度 pShadowEffect->setColor(QColor(0, 0, 0, 90)); // 阴影的颜色 pShadowEffect->setOffset(0, 0); // 水平和垂直偏移量 view()->setGraphicsEffect(pShadowEffect); QApplication::setEffectEnabled(Qt::UI_AnimateCombo, false); } } CustomComboBox::~CustomComboBox() { } void CustomComboBox::showPopup() { QComboBox::showPopup(); if (nullptr != view()) { view()->setMinimumWidth(width() + LISTVIEW_MARGIN * 2); } QWidget *popup = findChild(); if (nullptr != popup) { popup->move(mapToGlobal(QPoint(-LISTVIEW_MARGIN, height() - LISTVIEW_MARGIN + 4))); } }