Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a SIGNAL for QTableWidget from keyboard?

I have a table and move around inside with left, right, up, down buttons. Now I need to create a SIGNAL when I stay in a certain cell and press SPACE button. This SIGNAL should bring also the coordinate of that cell. I tried with standard signals of QTableWidget but it does not work. How can I solve this?

like image 689
trangan Avatar asked Dec 07 '25 08:12

trangan


1 Answers

Create a separate header file i.e. "customtable.h" and then in the Designer you can Promote the existing QTableWidget to this class.

class customTable:public QTableWidget
{
   Q_OBJECT
   public:
      customTable(QWidget* parent=0):QTableWidget(parent){}       
   protected:
      void keyPressEvent(QKeyEvent *e)
      {
         if(e->key()==Qt::Key_Space)
         {
            emit spacePressed(this->currentRow(),this->currentColumn());
         }
         else { QTableWidget::keyPressEvent(e); }
      }
   signals:
      spacePressed(int r, int c);
};
like image 80
lena Avatar answered Dec 10 '25 00:12

lena