PDA

View Full Version : How to enable shortcut keys for custom widgets?



Martin Drozdik
7th August 2012, 06:44
I am trying to implement a customized QTableView integrated to the clipboard:



#include <QTableView>
#include <QAction>

class GeneralTableView : public QTableView
{
Q_OBJECT
public:
explicit GeneralTableView(QWidget *parent = 0);

public slots:
void copy();

protected:
QAction* copyAction_;
};

GeneralTableView::GeneralTableView(QWidget *parent) :
QTableView(parent)
{
copyAction_ = new QAction(this);
copyAction_->setShortcut(QKeySequence::Copy);
connect(copyAction_, SIGNAL(triggered()),
this, SLOT(copy()));
}


But copy() does not get executed when I hit ctrl+c. Only some default version of copy gets called. This copies only one cell in the clipboard and doesn't call my copy(). How can I fix this?

sonulohani
7th August 2012, 09:51
It will only get trigger when you have something to copy. Since you dont have anything then how it would get trigger? What it will copy?

Martin Drozdik
7th August 2012, 09:57
I have an implementation for copy(), I just did not want to include it here for brevity. If I call copy() in another way, for example from a context menu, it does what it is supposed to do. It copies the entire selection to the clipboard. My problem is that it doesn't get called when I hit ctrl+c.