Results 1 to 3 of 3

Thread: Table Shortcuts Problem

  1. #1
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Table Shortcuts Problem

    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....
    Do what u r afraid to do, and the death of fear is sure.

  2. #2
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Table Shortcuts Problem

    guys please reply ....
    Do what u r afraid to do, and the death of fear is sure.

  3. #3
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Table Shortcuts Problem

    Have you see something message in console after connect?
    And have you try use this class not as dll ?
    a life without programming is like an empty bottle

Similar Threads

  1. Postgresql QSqlRelationalTableModel empty table
    By RolandHughes in forum Qt Programming
    Replies: 0
    Last Post: 12th November 2008, 17:18
  2. Table header section click problem
    By Khal Drogo in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2008, 22:31
  3. I have a problem to modify table
    By Abk in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 20:11
  4. Table Model / View Problem -- Data Not Displaying
    By jhendersen in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2007, 06:45
  5. Keyboard shortcuts problem.
    By Lemming in forum Qt Programming
    Replies: 4
    Last Post: 5th April 2006, 16:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.