Results 1 to 7 of 7

Thread: how can to receive the Real-time keyEvent in the QTableView?

  1. #1

    Smile how can to receive the Real-time keyEvent in the QTableView?

    When I DoubleClicked one cell in the table , the cursor will set in the cell ,
    and now the KeyEvent() of the QTableView will not receive any signal of the Keyboard...

    I think the reason is the cell is a QStandModelItem ,so it can't receive the signal KeyEvent() of the QTableView...

    So how can I to receive the real-time signal of the QTableView ,when I input one word in the cells ,will receive a signal...

    Hope you help...

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how can to receive the Real-time keyEvent in the QTableView?

    how do you process key events? did you inherit QTableView and overrode keyPressEvent or you installed event filter for QTableView object? if you use last approach then you should try to install event filter on QTableView's viewport.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3

    Talking Re: how can to receive the Real-time keyEvent in the QTableView?

    Quote Originally Posted by spirit View Post
    how do you process key events? did you inherit QTableView and overrode keyPressEvent or you installed event filter for QTableView object? if you use last approach then you should try to install event filter on QTableView's viewport.
    Yes ,I inherit QTableView and overrode the KeyPressEvent ...
    For this,How can I to receive the keyEvent in the QTablleView,

    Thank you very much.

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how can to receive the Real-time keyEvent in the QTableView?

    can you provide compilable example which reproduces the problem?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5

    Unhappy Re: how can to receive the Real-time keyEvent in the QTableView?

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "cgTableView.h"
    3.  
    4. #include <QTableView>
    5. #include <qDebug>
    6.  
    7. cgTableView::cgTableView(QWidget *parent)
    8. :QTableView(parent)
    9. {
    10. mpmain = (mainwindow*)parent;
    11. mdata = new cgItemModel();
    12. mselections = new cgItemSelectModel(mdata);
    13. setModel(mdata);
    14. setSelectionModel(mselections);
    15.  
    16. QList<QString> list;
    17. list.append("Record");
    18. list.append("In");
    19. list.append("Stop");
    20. list.append("Out");
    21. list.append("property");
    22.  
    23. mdata->setHorizontalHeaderLabels(list);
    24. setColumnWidth(0, 300);
    25.  
    26. //grabKeyboard ();
    27.  
    28. connect(this,SIGNAL(pressed(const QModelIndex)),this,SLOT(slot_pressed(const QModelIndex)));
    29. connect(mdata,SIGNAL(dataChanged(const QModelIndex , const QModelIndex )),
    30. this,SLOT(slot_dataChanged(const QModelIndex , const QModelIndex )));
    31. connect(mdata,SIGNAL(itemChanged ( QStandardItem * )),this,SLOT(slot_itemChange( QStandardItem * )));
    32. }
    33.  
    34. cgTableView::~cgTableView()
    35. {
    36.  
    37. }
    38.  
    39. void cgTableView::addItem()
    40. {
    41. mdata->appendRow(item);
    42. }
    43.  
    44. void cgTableView::remItem()
    45. {
    46. int index = currentIndex().row();
    47. mdata->removeRow(index);
    48. }
    49.  
    50. void cgTableView::insItem()
    51. {
    52. int index = currentIndex().row();
    53. if( index > 0)
    54. {
    55. mdata->insertRow( index , item );
    56. }
    57. else
    58. {
    59. mdata->insertRow( 0 , item );
    60. }
    61. }
    62.  
    63. int cgTableView::getIndex()
    64. {
    65. int index = currentIndex().row();
    66. return index;
    67. }
    68.  
    69. int cgTableView::getRowCount()
    70. {
    71. int rowCount = mdata->rowCount();
    72. return rowCount;
    73. }
    74.  
    75. void cgTableView::slot_pressed ( const QModelIndex & index )
    76. {
    77. int ind = currentIndex().row();
    78. int rowCount = mdata->rowCount();
    79. mpmain->tablePressed( ind , rowCount );
    80. }
    81.  
    82. void cgTableView::slot_dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight)
    83. {
    84. qDebug()<<"*** slot_dataChanged ***";
    85. int ind = currentIndex().row();
    86. QModelIndex index = mdata->index(currentIndex().row(),currentIndex().column());
    87. QString strdata = mdata->data( index ).toString ();
    88.  
    89. mpmain->setItemData(ind ,strdata);
    90. }
    91.  
    92. void cgTableView::slot_itemChange( QStandardItem * item)
    93. {
    94. qDebug()<<"*** slot_itemChange ***";
    95. QModelIndex index = mdata->index(currentIndex().row(),currentIndex().column());
    96. QString strdata = mdata->data( index ).toString ();
    97. }
    98.  
    99. void cgTableView::keyPressEvent ( QKeyEvent * event )
    100. {
    101. QTableView::keyPressEvent(event);
    102. }
    103.  
    104. void cgTableView::actionEvent ( QActionEvent * event )
    105. {
    106.  
    107. }
    108.  
    109. void cgTableView::childEvent ( QChildEvent * event )
    110. {
    111.  
    112. }
    113.  
    114. //bool cgTableView::event ( QEvent * event )
    115. //{
    116. // qDebug()<<"cgTableView::event ( QEvent * event )";
    117. // return true;
    118. //}
    119.  
    120. void cgTableView::inputMethodEvent ( QInputMethodEvent * event )
    121. {
    122.  
    123. }
    124.  
    125. void cgTableView::tabletEvent ( QTabletEvent * event )
    126. {
    127.  
    128. }
    129.  
    130. void cgTableView::paintEvent ( QPaintEvent * event )
    131. {
    132. qDebug()<<"paintEvent ( QPaintEvent * event )";
    133. QTableView::paintEvent(event);
    134. }
    135.  
    136. void cgTableView::setChildItem( int row ,int column, QStandardItem * item )
    137. {
    138. QStandardItemModel *model = dynamic_cast<QStandardItemModel *>(mdata);
    139. }
    140.  
    141. void cgTableView::tableRowsInserted()
    142. {
    143. QModelIndex index = mdata->index(currentIndex().row(),currentIndex().column());
    144. rowsInserted(index,0,0);
    To copy to clipboard, switch view to plain text mode 

    This is the QTableView Program ,and I set many function to receive ,but fail.
    In the functions there is a keyPressEvent() ,if the cursor in the cells ,this evnet will not be trigger ...

    So I don't know how to receive Real-time signal of the QTabelView ...

  6. #6
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how can to receive the Real-time keyEvent in the QTableView?

    Your approach is not good. In Model/View architecture the main idea is to separate data (model) from it's presentation (view), but you are connecting those things in one class.

    But if you really want such approach then there is QTableWidget which is data container and view at once.

    And finally: what do you need those key events for? I suppose that for editing items - am I right? Then you should take a look into delegates, as they are used for custom presentation in a view and for custom editors for data presenting in view. And you can get there key events from cells.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  7. #7

    Default Re: how can to receive the Real-time keyEvent in the QTableView?

    I suppose that for editing items - am I right?

    yes, you are right,then I will have a try to use the delegates in the model.
    thanks!

Similar Threads

  1. Replies: 2
    Last Post: 21st January 2011, 17:12
  2. Replies: 1
    Last Post: 15th April 2009, 09:00
  3. PlotWin with scroll on real time
    By looki in forum Qwt
    Replies: 5
    Last Post: 8th August 2008, 15:40
  4. Display the camera frame in real time
    By alex_lue in forum Qt Programming
    Replies: 8
    Last Post: 27th July 2007, 10:31
  5. Displaying real time images
    By Sheetal in forum Qt Programming
    Replies: 9
    Last Post: 22nd February 2007, 11:29

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.