diff --git a/include/ui/noscrollcombobox.h b/include/ui/noscrollcombobox.h index 59c680a3..65b6ab5b 100644 --- a/include/ui/noscrollcombobox.h +++ b/include/ui/noscrollcombobox.h @@ -13,6 +13,8 @@ public: void setTextItem(const QString &text); void setNumberItem(int value); void setHexItem(uint32_t value); + void setEditable(bool editable); + void setLineEdit(QLineEdit *edit); private: void setItem(int index, const QString &text); diff --git a/src/ui/noscrollcombobox.cpp b/src/ui/noscrollcombobox.cpp index ee778df5..a634af7f 100644 --- a/src/ui/noscrollcombobox.cpp +++ b/src/ui/noscrollcombobox.cpp @@ -22,6 +22,18 @@ NoScrollComboBox::NoScrollComboBox(QWidget *parent) this->setValidator(validator); } +// On macOS QComboBox::setEditable and QComboBox::setLineEdit will override our changes to the focus policy, so we enforce it here. +void NoScrollComboBox::setEditable(bool editable) { + auto policy = focusPolicy(); + QComboBox::setEditable(editable); + setFocusPolicy(policy); +} +void NoScrollComboBox::setLineEdit(QLineEdit *edit) { + auto policy = focusPolicy(); + QComboBox::setLineEdit(edit); + setFocusPolicy(policy); +} + void NoScrollComboBox::wheelEvent(QWheelEvent *event) { // Only allow scrolling to modify contents when it explicitly has focus.