PDA

View Full Version : Table Shortcuts Problem



ankurjain
26th April 2006, 12:20
Hi guys,

Following is my code. i get the table by a dll. My dll makes the table and gives the context menu over it. I set shortcuts for these also, but they are not working.



// dll cpp file QGrid.cpp

#include <QtGui>
#include "QGrid.h"
#include <QMessageBox>

/* Constructor creating the grid with 'r' rows 'c' columns and 'parent' parent.
* It creates context menu for the grid.
*/

QGrid::QGrid(int r, int c,QWidget *parent) : QTableWidget(r,c,parent)
{
createActions();
setUpContextMenu();
int change = -1;
int rowNo = -1;
}
/*
Constructor creating the grid with 0 rows ,0 columnms & 'parent' parent.
It creates context menu for the grid.
*/


QGrid::QGrid(QWidget *parent) : QTableWidget(parent)
{
createActions();
setUpContextMenu();
int change = -1;
int rowNo = -1;
}

/* Creates the context menu for the grid. */

void QGrid::setUpContextMenu()
{
/*
This block adds the context menu over the vertical headers.
*/
verticalHeader()->addAction(cutAct);
verticalHeader()->addAction(copyAct);
verticalHeader()->addAction(deleteAct);
verticalHeader()->addAction(pasteAct);
verticalHeader()->addAction(undoAct);
verticalHeader()->addAction(redoAct);
verticalHeader()->addAction(addrowAct);
verticalHeader()->addAction(deleterowAct);
verticalHeader()->setContextMenuPolicy(Qt::ActionsContextMenu);

/*
This block adds the context menu over the grid.
*/
addAction(cutAct);
addAction(copyAct);
addAction(pasteAct);
addAction(deleteAct);
addAction(undoAct);
addAction(redoAct);
addAction(addrowAct);
addAction(deleterowAct);

setContextMenuPolicy(Qt::ActionsContextMenu);
}
/*
This function is creating the actual actions. Following functions are provided:
Cut, Copy, Paste, Undo, Redo, Addrow, Deleterow.
*/
void QGrid::createActions()
{
copyAct = new QAction(QIcon(":/images/copy.png"), "&Copy", this);
copyAct->setShortcut(tr("Ctrl+C"));
copyAct->setShortcutContext(Qt::ApplicationShortcut);
copyAct->setStatusTip(tr("Copy the current selection's contents to the "
"clipboard"));
connect(copyAct, SIGNAL(triggered()), this, SLOT(copy()));

.....
}


/*
Copies a selected cell.
*/
void QGrid::copy()
{
QMessageBox::information(this,"COPY","From dll");
int ind = 0;
QString str,str1;
int no = this->currentRow();


foreach (QTableWidgetItem *i,this->selectedItems())
{
// this->clearSelection();
QString strPrint(i->text());
strPrint+="\t";
str+=strPrint;
clip->setText(str,QClipboard::Clipboard);
}

}




//dll header file QGrid.h

#ifndef QGRID_H
#define QGRID_H
#include <QtCore/qglobal.h>
#include <QtGui/QDialog>
#include <QAction>
#include <QTableWidget>

#define ISCUT 0
#define NOTCUT -1
#define ISNEWROW 1
#define NOTNEWROW -1
#define ISDELROW 2
#define NOTDELROW -1

#ifdef BUILD_QGRID
# ifdef Q_CC_MSVC
# define QGRID_EXPORT Q_DECL_EXPORT
# else
# define QGRID_EXPORT Q_DECL_IMPORT
# endif
#else
# define QGRID_EXPORT
#endif
/*
Class exported or imported depending on the definition of QGRID_EXPORT
*/
class QGRID_EXPORT QGrid : public QTableWidget
{
Q_OBJECT
public:
QGrid(int c,int r,QWidget *parent = 0);
QGrid(QWidget *parent = 0);
QClipboard *clip;
int rowNo;
int change;
private:
QAction *copyAct;
public slots:
void copy();
....
public:
void setUpContextMenu();
void createActions();
};
#endif





//main application

#include <QtGui>
#include "QGrid.h"

int main(int argc,char **argv)
{
QApplication app(argc,argv);

QGrid *grid = new QGrid(4,4);
grid->show();

return app.exec();
}




Here my keyboard shorcut isn't working. Please Help....

ankurjain
27th April 2006, 09:03
guys please reply .... :(

zlatko
27th April 2006, 09:31
Have you see something message in console after connect?
And have you try use this class not as dll ?