Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Ctrl+c KeySeq. not working with QAbstractSpinbox

Ctrl+c KeySeq. not working with QAbstractSpinbox

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 270 Views
  • 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.
  • thaiboydigitalT Offline
    thaiboydigitalT Offline
    thaiboydigital
    wrote on last edited by thaiboydigital
    #1

    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 ?

    JonBJ 1 Reply Last reply
    0
    • thaiboydigitalT 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 ?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

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

      thaiboydigitalT 1 Reply Last reply
      0
      • JonBJ 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!

        thaiboydigitalT Offline
        thaiboydigitalT Offline
        thaiboydigital
        wrote on last edited by
        #3

        @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
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved