* fix QComboBox popup leaking shortcuts

This commit is contained in:
Garux 2023-07-03 12:26:20 +06:00
parent 2b3a34b299
commit 7396eef067
4 changed files with 28 additions and 8 deletions

View File

@ -41,8 +41,8 @@
#include <QButtonGroup>
#include <QRadioButton>
#include <QFrame>
#include <QComboBox>
#include "gtkutil/spinbox.h"
#include "gtkutil/combobox.h"
/*--------------------------------
@ -258,7 +258,7 @@ bool DoDoorsBox( DoorRS* rs ){
auto form = new QFormLayout( &dialog );
form->setSizeConstraint( QLayout::SizeConstraint::SetFixedSize );
{
form->addRow( "Door Front/Back Texture", comboMain = new QComboBox );
form->addRow( "Door Front/Back Texture", comboMain = new ComboBox );
char buffer[256];
comboMain->addItems( LoadListStore( GetFilename( buffer, "bt/door-tex.txt" ) ) );
comboMain->setEditable( true );
@ -272,7 +272,7 @@ bool DoDoorsBox( DoorRS* rs ){
checkScaleMainV->setChecked( true );
}
{
form->addRow( "Door Trim Texture", comboTrim = new QComboBox );
form->addRow( "Door Trim Texture", comboTrim = new ComboBox );
char buffer[256];
comboTrim->addItems( LoadListStore( GetFilename( buffer, "bt/door-tex-trim.txt" ) ) );
comboTrim->setEditable( true );

View File

@ -33,8 +33,8 @@
#include <QSlider>
#include <QLabel>
#include <QPushButton>
#include <QComboBox>
#include <QCheckBox>
#include "gtkutil/combobox.h"
static void OnColor( PackedColour& clr ){
@ -132,7 +132,7 @@ void DoConfigDialog(){
form_add_slider( form, portals.clip_range, 64, 8192, "Clip range = ", "", false );
}
{
auto combo = new QComboBox;
auto combo = new ComboBox;
vbox->addWidget( combo );
combo->addItem( "Z-Buffer Test and Write (recommended for solid or no polygons)" );
combo->addItem( "Z-Buffer Test Only (recommended for transparent polygons)" );

View File

@ -23,12 +23,17 @@
#include <QComboBox>
#include <QKeyEvent>
#include <QAbstractItemView>
/// @brief Subclassed QComboBox not comsuming Enter key (why does it do it? works as expected for editable ComboBox)
/// purpose is to have working confirmation by Enter in dialogs
/// fixme unsolved crude problem here is triggering arrows, page, home, end global shortcuts when pressed in popup; even if modal dialog 😱
/// +fixes crude problem: triggering arrows, page, home, end global shortcuts when pressed in popup; even if modal dialog 😱
class ComboBox : public QComboBox
{
public:
ComboBox( QWidget *parent = nullptr ) : QComboBox( parent ){
this->view()->installEventFilter( this );
}
protected:
void keyPressEvent( QKeyEvent *event ) override {
if( event->key() == Qt::Key_Enter
@ -38,4 +43,19 @@ protected:
}
QComboBox::keyPressEvent( event );
}
bool eventFilter( QObject *obj, QEvent *event ) override {
// the popup leaks ALL shortcuts 😱 to global space 😱😱😱 besides ones handled in QComboBoxPrivateContainer::eventFilter
// it very bad, can interact with the editor while in modal dialog and crash it
// filter them all besides ones, taken by the other filter
if( event->type() == QEvent::ShortcutOverride ) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>( event );
if( keyEvent->key() != Qt::Key_Return
&& keyEvent->key() != Qt::Key_Enter
&& !keyEvent->matches( QKeySequence::Cancel ) ){
event->accept();
return true;
}
}
return QObject::eventFilter( obj, event ); // standard event processing
}
};

View File

@ -51,7 +51,7 @@
#include <QKeyEvent>
#include <QApplication>
#include <QButtonGroup>
#include <QComboBox>
#include "gtkutil/combobox.h"
#include "os/path.h"
#include "eclasslib.h"
@ -651,7 +651,7 @@ class ListAttribute final : public EntityAttribute
public:
ListAttribute( const char* key, const ListAttributeType& type ) :
m_key( key ),
m_combo( new QComboBox ),
m_combo( new ComboBox ),
m_type( type ){
for ( const auto&[ name, value ] : type )
{