Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

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

    General and Desktop
    1
    2
    1531
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      Jake007 last edited by

      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);
      }@


      Code is poetry

      1 Reply Last reply Reply Quote 0
      • J
        Jake007 last edited by

        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.


        Code is poetry

        1 Reply Last reply Reply Quote 0
        • First post
          Last post