Unsolved Tastenkürzel in QLineEditor Anzeigen
-
Hallo.
Ich brauche code, für Tastenkürzel in QLineEdit..und zwar wenn in QlineEdit(TInPut) Tasten Drückt, soll die in QlineEdit(TInPut) anzeigen
so wie Z.b In QT-Creater.
danke Vorraus
-
-
ich habe das gefunden
https://stackoverflow.com/questions/13487352/how-to-create-a-hotkey-field-in-qt
aber kopiere nich wie das funktionieren soll.
-
@val78
was gefällt dir an QKeysequenceEdit nicht?!
Entspricht genau deiner Beschreibung -
Ich habe ich so
neukurz.cpp #include "neukurz.h" #include "ui_neukurz.h" NeuKurz::NeuKurz(QWidget *parent) : QDialog(parent), ui(new Ui::NeuKurz) { ui->setupUi(this); } NeuKurz::~NeuKurz() { delete ui; } void QLineEditHotKey::keyPressEvent( QKeyEvent * event ) { int keyInt = event->key(); Qt::Key key = static_cast<Qt::Key>(keyInt); // Handle unknown keys if( key == Qt::Key_unknown ) return; // Pressing Esc or Backspace will clear the content if( key == Qt::Key_Escape || key == Qt::Key_Backspace ) { setText(nullptr); return; } // Empty means a special key like F5, Delete, Home etc if( event->text().isEmpty() ) return; // Checking for key combinations Qt::KeyboardModifiers modifiers = event->modifiers(); if(modifiers.testFlag(Qt::NoModifier)) return; if(modifiers.testFlag(Qt::ShiftModifier)) keyInt += Qt::SHIFT; if(modifiers.testFlag(Qt::ControlModifier)) keyInt += Qt::CTRL; if(modifiers.testFlag(Qt::AltModifier)) keyInt += Qt::ALT; setText( QKeySequence(keyInt).toString(QKeySequence::NativeText) ); } void NeuKurz::on_buttonBox_accepted() { }
nuekurz.h #ifndef NEUKURZ_H #define NEUKURZ_H #include <QLineEdit> #include <QDialog> #include <QKeyEvent> namespace Ui { class NeuKurz; } class NeuKurz : public QDialog { Q_OBJECT public: explicit NeuKurz(QWidget *parent = nullptr); ~NeuKurz(); private slots: void on_buttonBox_accepted(); private: Ui::NeuKurz *ui; }; class QLineEditHotKey: public QLineEdit { public: QLineEditHotKey( QWidget* pParent = nullptr); ~QLineEditHotKey(){} protected: void keyPressEvent ( QKeyEvent * event ); }; #endif // NEUKURZ_H
aber Funktioniert nicht . zeigt auch kein fehler!