Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Ctrl+c KeySeq. not working with QAbstractSpinbox



  • 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 ?



  • @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!



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

Log in to reply