瀏覽代碼

1、修改了customcombobox

Apple 2 天之前
父節點
當前提交
de0d6f585a
共有 2 個文件被更改,包括 19 次插入0 次删除
  1. 11 0
      common/combox/customcombobox.cpp
  2. 8 0
      common/combox/customcombobox.h

+ 11 - 0
common/combox/customcombobox.cpp

@@ -4,6 +4,7 @@
 #include <QListView>
 #include <QDebug>
 #include <QStyleFactory>
+#include <QWheelEvent>
 
 CustomComboBox::CustomComboBox(QWidget *parent)
     : QComboBox(parent)
@@ -47,3 +48,13 @@ void CustomComboBox::showPopup()
         popup->move(mapToGlobal(QPoint(-LISTVIEW_MARGIN, height() - LISTVIEW_MARGIN + 4)));
     }
 }
+
+
+void CustomComboBox::wheelEvent(QWheelEvent *event)
+{
+    if (m_wheelDisabled) {
+        event->ignore(); // 禁用滚轮修改内容
+    } else {
+        QComboBox::wheelEvent(event); // 正常处理滚轮事件
+    }
+}

+ 8 - 0
common/combox/customcombobox.h

@@ -20,8 +20,16 @@ public:
 
     //重写下拉框弹出位置
     void showPopup() override;
+    /* 禁用滚轮修改内容 */
+    void setWheelDisabled(bool disabled = true) { m_wheelDisabled = disabled; }
+
+
+protected:
+    void wheelEvent(QWheelEvent *event) override;
+
 private:
     const int LISTVIEW_MARGIN = 12; // QAbstractItemView边距(阴影宽度)
+    bool m_wheelDisabled = false; // 是否禁用滚轮修改内容
 };
 
 #endif // _CUSTOMCOMBOBOX_H_