Qt Forum

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

    Solved Ctrl+c KeySeq. not working with QAbstractSpinbox

    General and Desktop
    2
    3
    106
    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.
    • thaiboydigital
      thaiboydigital last edited by thaiboydigital

      Hello, i have a class derived from QAbstractSpinBox, i need to make special Ctrl+C keyboard shortcut. So, how i do this :
      I added this code to the class constructor :

       auto shortcut = new QShortcut(QKeySequence(tr("Ctrl+C", "Copy")), this);
             connect(shortcut, &QShortcut::activated, this, []() {
                qDebug() << "HAPPEN !";
             });
      

      but qDebug doesn't give anything. But Also it works when i change Ctrl+C to for example Ctrl+G

       auto shortcut = new QShortcut(QKeySequence(tr("Ctrl+G", "Copy")), this);
             connect(shortcut, &QShortcut::activated, this, []() {
                qDebug() << "HAPPEN !";
             });
      

      As i suppose, QAbstractSpinBox has its default KeySequences that blocks my CTRL+C , or smt like this. I tried to overload keypressevent and keyreleaseevent(thought they intercept Ctrl+c, but it didnt help. Is there way to do it ?

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @thaiboydigital last edited by JonB

        @thaiboydigital
        I don't know if this has anything to do with QAbstractSpinBox or any other widget. On Windows/Linux Ctrl+C is "special", in that it interrupts program execution. If you really need to use that shortcut you'll need to Google around to see what is needed/whether to change that behaviour so that specifically Ctrl+C can be used as a shortcut....

        EDIT ... or maybe not, since OP has just solved in post below!

        thaiboydigital 1 Reply Last reply Reply Quote 0
        • thaiboydigital
          thaiboydigital @JonB last edited by

          @jonb , i just found the solution, i just overloaded KeyPressEvent on abstractSpinBox.

          and inserted this here :

          void SpinBox::keyPressEvent(QKeyEvent *event) {
          if ((event == QKeySequence::Copy))
                    lineEdit()->copy();
          }
          
          1 Reply Last reply Reply Quote 1
          • First post
            Last post