Skip to content

Commit

Permalink
Preserve NoScrollComboBox focus policy on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinRichards committed Aug 14, 2024
1 parent 2c1d363 commit 256f6ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/ui/noscrollcombobox.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class NoScrollComboBox : public QComboBox
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);
Expand Down
12 changes: 12 additions & 0 deletions src/ui/noscrollcombobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 256f6ee

Please sign in to comment.