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.

Qt Code:
  1. // dll cpp file QGrid.cpp
  2.  
  3. #include <QtGui>
  4. #include "QGrid.h"
  5. #include <QMessageBox>
  6.  
  7. /* Constructor creating the grid with 'r' rows 'c' columns and 'parent' parent.
  8.  * It creates context menu for the grid.
  9.  */
  10.  
  11. QGrid::QGrid(int r, int c,QWidget *parent) : QTableWidget(r,c,parent)
  12. {
  13. createActions();
  14. setUpContextMenu();
  15. int change = -1;
  16. int rowNo = -1;
  17. }
  18. /*
  19. Constructor creating the grid with 0 rows ,0 columnms & 'parent' parent.
  20. It creates context menu for the grid.
  21.  */
  22.  
  23.  
  24. QGrid::QGrid(QWidget *parent) : QTableWidget(parent)
  25. {
  26. createActions();
  27. setUpContextMenu();
  28. int change = -1;
  29. int rowNo = -1;
  30. }
  31.  
  32. /* Creates the context menu for the grid. */
  33.  
  34. void QGrid::setUpContextMenu()
  35. {
  36. /*
  37. This block adds the context menu over the vertical headers.
  38.  */
  39. verticalHeader()->addAction(cutAct);
  40. verticalHeader()->addAction(copyAct);
  41. verticalHeader()->addAction(deleteAct);
  42. verticalHeader()->addAction(pasteAct);
  43. verticalHeader()->addAction(undoAct);
  44. verticalHeader()->addAction(redoAct);
  45. verticalHeader()->addAction(addrowAct);
  46. verticalHeader()->addAction(deleterowAct);
  47. verticalHeader()->setContextMenuPolicy(Qt::ActionsContextMenu);
  48.  
  49. /*
  50. This block adds the context menu over the grid.
  51.  */
  52. addAction(cutAct);
  53. addAction(copyAct);
  54. addAction(pasteAct);
  55. addAction(deleteAct);
  56. addAction(undoAct);
  57. addAction(redoAct);
  58. addAction(addrowAct);
  59. addAction(deleterowAct);
  60.  
  61. setContextMenuPolicy(Qt::ActionsContextMenu);
  62. }
  63. /*
  64. This function is creating the actual actions. Following functions are provided:
  65. Cut, Copy, Paste, Undo, Redo, Addrow, Deleterow.
  66.  */
  67. void QGrid::createActions()
  68. {
  69. copyAct = new QAction(QIcon(":/images/copy.png"), "&Copy", this);
  70. copyAct->setShortcut(tr("Ctrl+C"));
  71. copyAct->setShortcutContext(Qt::ApplicationShortcut);
  72. copyAct->setStatusTip(tr("Copy the current selection's contents to the "
  73. "clipboard"));
  74. connect(copyAct, SIGNAL(triggered()), this, SLOT(copy()));
  75.  
  76. .....
  77. }
  78.  
  79.  
  80. /*
  81. Copies a selected cell.
  82.  */
  83. void QGrid::copy()
  84. {
  85. QMessageBox::information(this,"COPY","From dll");
  86. int ind = 0;
  87. QString str,str1;
  88. int no = this->currentRow();
  89.  
  90.  
  91. foreach (QTableWidgetItem *i,this->selectedItems())
  92. {
  93. // this->clearSelection();
  94. QString strPrint(i->text());
  95. strPrint+="\t";
  96. str+=strPrint;
  97. clip->setText(str,QClipboard::Clipboard);
  98. }
  99.  
  100. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. //dll header file QGrid.h
  2.  
  3. #ifndef QGRID_H
  4. #define QGRID_H
  5. #include <QtCore/qglobal.h>
  6. #include <QtGui/QDialog>
  7. #include <QAction>
  8. #include <QTableWidget>
  9.  
  10. #define ISCUT 0
  11. #define NOTCUT -1
  12. #define ISNEWROW 1
  13. #define NOTNEWROW -1
  14. #define ISDELROW 2
  15. #define NOTDELROW -1
  16.  
  17. #ifdef BUILD_QGRID
  18. # ifdef Q_CC_MSVC
  19. # define QGRID_EXPORT Q_DECL_EXPORT
  20. # else
  21. # define QGRID_EXPORT Q_DECL_IMPORT
  22. # endif
  23. #else
  24. # define QGRID_EXPORT
  25. #endif
  26. /*
  27. Class exported or imported depending on the definition of QGRID_EXPORT
  28.  */
  29. class QGRID_EXPORT QGrid : public QTableWidget
  30. {
  31. Q_OBJECT
  32. public:
  33. QGrid(int c,int r,QWidget *parent = 0);
  34. QGrid(QWidget *parent = 0);
  35. QClipboard *clip;
  36. int rowNo;
  37. int change;
  38. private:
  39. QAction *copyAct;
  40. public slots:
  41. void copy();
  42. ....
  43. public:
  44. void setUpContextMenu();
  45. void createActions();
  46. };
  47. #endif
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. //main application
  2.  
  3. #include <QtGui>
  4. #include "QGrid.h"
  5.  
  6. int main(int argc,char **argv)
  7. {
  8. QApplication app(argc,argv);
  9.  
  10. QGrid *grid = new QGrid(4,4);
  11. grid->show();
  12.  
  13. return app.exec();
  14. }
To copy to clipboard, switch view to plain text mode 


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