#include "customcombobox.h" #include #include #include #include #include #include CustomComboBox::CustomComboBox(QWidget *parent) : QComboBox(parent) , m_nMargin(0) { setStyle(QStyleFactory::create("Windows")); setView(new QListView()); view()->window()->setWindowFlags(Qt::Popup|Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint); view()->window()->setAttribute(Qt::WA_TranslucentBackground); QGraphicsDropShadowEffect *pShadowEffect = new QGraphicsDropShadowEffect(this); pShadowEffect->setBlurRadius(10); // 模糊度 pShadowEffect->setColor(QColor(0, 0, 0, 76)); // 阴影的颜色 pShadowEffect->setOffset(0, 0); // 水平和垂直偏移量 view()->setGraphicsEffect(pShadowEffect); QTimer::singleShot(0, this, [=] { view()->setMinimumWidth(width()+m_nMargin*2); }); } CustomComboBox::~CustomComboBox() { qDebug()<<__func__; } void CustomComboBox::showPopup() { QComboBox::showPopup(); QWidget *popup = findChild(); popup->move(mapToGlobal(QPoint(-m_nMargin, height()))); }