customcombobox.h 712 B

1234567891011121314151617181920212223242526
  1. #ifndef CUSTOMCOMBOBOX_H
  2. #define CUSTOMCOMBOBOX_H
  3. #include <QComboBox>
  4. /**
  5. * @brief 1、使用此类绘制下拉框阴影需要在样式表中设置QAbstractItemView {margin: LISTVIEW_MARGIN;}
  6. * 否则阴影会被遮挡
  7. * 2、调用函数setViewShadowEffect()设置下拉框阴影
  8. */
  9. class CustomComboBox : public QComboBox
  10. {
  11. public:
  12. explicit CustomComboBox(QWidget *parent = nullptr);
  13. ~CustomComboBox();
  14. /* 设置下拉框阴影 */
  15. void setViewShadowEffect();
  16. //重写下拉框弹出位置
  17. void showPopup() override;
  18. private:
  19. const int LISTVIEW_MARGIN = 12; // QAbstractItemView边距(阴影宽度)
  20. };
  21. #endif // CUSTOMCOMBOBOX_H