Prechádzať zdrojové kódy

UI: Fix crash when pressing `tab` key in rename

tuduweb 3 rokov pred
rodič
commit
34e346a011

+ 19 - 0
UI/visibility-item-widget.cpp

@@ -7,6 +7,7 @@
 #include <QHBoxLayout>
 #include <QMessageBox>
 #include <QLabel>
+#include <QKeyEvent>
 
 VisibilityItemWidget::VisibilityItemWidget(obs_source_t *source_)
 	: source(source_),
@@ -144,6 +145,24 @@ void VisibilityItemDelegate::paint(QPainter *painter,
 	widget->SetColor(palette.color(group, role), active, selected);
 }
 
+bool VisibilityItemDelegate::eventFilter(QObject *object, QEvent *event)
+{
+	QWidget *editor = qobject_cast<QWidget *>(object);
+	if (!editor)
+		return false;
+
+	if (event->type() == QEvent::KeyPress) {
+		QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
+
+		if (keyEvent->key() == Qt::Key_Tab ||
+		    keyEvent->key() == Qt::Key_Backtab) {
+			return false;
+		}
+	}
+
+	return QStyledItemDelegate::eventFilter(object, event);
+}
+
 void SetupVisibilityItem(QListWidget *list, QListWidgetItem *item,
 			 obs_source_t *source)
 {

+ 3 - 0
UI/visibility-item-widget.hpp

@@ -47,6 +47,9 @@ public:
 
 	void paint(QPainter *painter, const QStyleOptionViewItem &option,
 		   const QModelIndex &index) const override;
+
+protected:
+	bool eventFilter(QObject *object, QEvent *event) override;
 };
 
 void SetupVisibilityItem(QListWidget *list, QListWidgetItem *item,