ShortcutsPage::ShortcutsPage(QWidget *parent) : QWidget(parent), m_treeModel( NULL ), ui( new Ui::ShortcutsPage ) { ui->setupUi(this); m_treeModel = new QStandardItemModel(this); treeModelLoadShortcutsSetting(); ui->treeView->setModel(m_treeModel); ui->treeView->resizeColumnToContents(0); connect(ui->treeView, SIGNAL(clicked(const QModelIndex&)), this, SLOT(tableItemClicked(const QModelIndex&))); connect(ui->keySeqLineEdit, SIGNAL(keyCaptured(QKeySequence)), this, SLOT(keyCapLineEditTextChanged(QKeySequence))); connect(ui->restoreShortcutsButton, SIGNAL(clicked()), this, SLOT(restoreShortcutsButtonClicked())); connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearButtonClicked())); }
void KeyCaptureLineEdit::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Control || event->key() == Qt::Key_Shift || event->key() == Qt::Key_Alt || event->key() == Qt::Key_Meta ) { // only modifier key is not allowed. qDebug() << "only!"; event->accept(); return; } int keyInt = event->key(); if (event->modifiers() & Qt::CTRL) { keyInt += Qt::CTRL; } if (event->modifiers() & Qt::SHIFT) { keyInt += Qt::SHIFT; } if (event->modifiers() & Qt::ALT) { keyInt += Qt::ALT; } if (event->modifiers() & Qt::META) { keyInt += Qt::META; } QKeySequence keySeq(keyInt); QString strKeySeq = keySeq.toString(QKeySequence::NativeText); emit keyCaptured(keySeq); this->setText(strKeySeq); }