本文介绍了如何通过键盘为QTableWidget创建信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张桌子,并用向左,向右,向上,向下按钮在内部移动.现在,当我停留在某个单元格中并按空格键时,需要创建一个信号.该信号还应带来该单元的坐标.我尝试使用QTableWidget的标准信号,但是它不起作用.我该如何解决?
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?
推荐答案
创建一个单独的头文件,即"customtable.h",然后在设计器中将现有的QTableWidget提升为此类.
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);
};
这篇关于如何通过键盘为QTableWidget创建信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!