customcombobox.h 833 B

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