CTRL+X/C/V/A for custom widgets



  • Hi!

    I'd like to assign cut, copy, paste and select all shortcuts to a QGraphicsView widget.
    If I do this using menus (which is how I'd like to) and assign each action with its corresponding shortcut, I override shortcuts for all other widget ( QTextEdit, QLineEdit ...).

    How can I solve this?

    If possible, I'd like to have this actions listed in QMenu with shortcuts.

    I also looked over an alternative, overriding QGraphicsView::keyPressEvent, and may question is, is Qt::key_Copy for ctrl+c?

    Thanks in advance.

    Regards,
    Jake

    EDIT:
    It works with default widgets. It does not work with inherited QTextEdit and overridden keyPressEvent();

    Code:
    @void ConsoleOutput::keyPressEvent(QKeyEvent *e)
    {
    switch(e->key())
    {
    case Qt::Key_Enter:
    case Qt::Key_Return:
    emit returnPressed();
    output("<br />");
    break;
    case Qt::Key_Left:
    case Qt::Key_Right:
    case Qt::Key_Up:
    case Qt::Key_Down:
    break;
    default:
    cursorToEnd();
    }

    if(myFirstInput)
    {
    myFirstInput = false;

    myOrg = this->toPlainText();
    myLen = this->toPlainText().length();
    }

    else if(e->key() == Qt::Key_Backspace)
    {
    if(toPlainText().size() < myLen)
    return;

    else if(toPlainText()[(toPlainText().size()-1)] == '\n')
    return;
    }

    QTextEdit::keyPressEvent(e);
    }@



  • I pinpointed the problem.
    It's because I set widget to read only. If I do not, it works as it should.

    In my opinion it's a bug. Can someone confirm this? Ctrl + a and ctrl + c should work even if it's read only, since data is not changed.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.