Skip to content

Commit

Permalink
Add custom property when pressing Enter with type combo focused
Browse files Browse the repository at this point in the history
This change also disables Enter for opening the combo box popup, fixing
the rather broken behavior (at least on Linux) that pressing Enter to
select a type will immediately re-open the popup. That only applies to
combo boxes in the Properties view, though.
  • Loading branch information
bjorn committed Dec 5, 2024
1 parent 8a36db5 commit 73e6373
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/tiled/propertyeditorwidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,18 @@ bool ComboBox::event(QEvent *event)
return QComboBox::event(event);
}

void ComboBox::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
case Qt::Key_Enter:
case Qt::Key_Return:
emit returnPressed();
return;
}

QComboBox::keyPressEvent(event);
}

void ComboBox::wheelEvent(QWheelEvent *event)
{
if (!hasFocus())
Expand Down
5 changes: 5 additions & 0 deletions src/tiled/propertyeditorwidgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ class ComboBox : public QComboBox
public:
ComboBox(QWidget *parent = nullptr);

signals:
/** This signal is emitted when the Return or Enter key is pressed. */
void returnPressed();

protected:
bool event(QEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
};

Expand Down
4 changes: 4 additions & 0 deletions src/tiled/variantmapproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,10 @@ QWidget *AddValueProperty::createEditor(QWidget *parent)
m_value = typeBox->itemData(index);
session::propertyType = typeBox->currentText();
});
connect(typeBox, &ComboBox::returnPressed, this, [this] {
if (!name().isEmpty())
emit addRequested();
});

typeBox->installEventFilter(this);

Expand Down

0 comments on commit 73e6373

Please sign in to comment.