December 8, 2010

xeroblast xeroblast
Lab Rat
91 posts

[SOLVED] QDate dateChanged() signal wont let me finished editing

 

hi,

i need to edit a date in my QTableWidget. when i double click the QTableWidget cell, QDateEdit widget will appear in the QTableWidget cell with its date according to the date on the QTableWidget cell before. when i am still selecting the date in the QDateEdit, the dateChanged() signal is emitted without letting me finished my edit.

any great ideas on how to go around this kind of problem?

thanx..

9 replies

December 8, 2010

Gerolf Gerolf
Area 51 Engineer
3210 posts

You can write your own delegate change that. But that’s interesting, the dateChanged() signal closes the edit, did I understand right? so you are editing the parts of the date step by step?

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

December 8, 2010

xeroblast xeroblast
Lab Rat
91 posts

yeah, it will close. and yes,kinda like editing step-by-step. let us say the current date is january 1 2010, when i change the month by clicking the up arrow on the right side of the widget, it will automatically close then the new date will appear as february 1 2010. and so with the days and years…

i dont have any ideas on how to implement this by waiting for me to finish it…

December 8, 2010

Gerolf Gerolf
Area 51 Engineer
3210 posts

If you create an delegate, you can overwrite some methods of the base implementation, but to do that, first have a look at QStyledItemdelegate / QItemDelegate and check, how it is done there.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

December 8, 2010

xeroblast xeroblast
Lab Rat
91 posts

thanx.. i alrady started it..

December 8, 2010

Volker Volker
Robot Herder
5428 posts

There is no such behavior if you do not set an item delegate. Qt uses QStyledItemDelegate [doc.trolltech.com] as a default. The date edit is only ended when you click on another cell oder press the return key.

This looks as if you use your own item delegate, that intercepts the edit/commit mechanism provided by Qt.

This short sample demonstrates the default behavior:

  1. #include <QApplication>
  2. #include <QTableWidget>
  3. #include <QDate>
  4.  
  5. int main(int argc, char **argv)
  6. {
  7.     QApplication a(argc, argv);
  8.  
  9.     QTableWidget tw;
  10.     tw.setRowCount(5);
  11.     tw.setColumnCount(3);
  12.  
  13.     QTableWidgetItem *twi = new QTableWidgetItem;
  14.     twi->setData(Qt::EditRole, QDate::currentDate());
  15.  
  16.     tw.setItem(0, 0, twi);
  17.     tw.show();
  18.  
  19.     return a.exec();
  20. }

December 9, 2010

xeroblast xeroblast
Lab Rat
91 posts

thanx to all your reply coz i now know about item delegate but there is someone in the other forum suggested about editingFinished() signal which works. never see editingFinished() signal in the docs.
none in the QDate, QDateEdit, QDateTime, QDateTimeEdit, QTime & QTimeEdit…

December 9, 2010

Volker Volker
Robot Herder
5428 posts

editingFinished() is a signal of

QAbstractSpinBox [doc.qt.nokia.com] (which is inherited by QDateTimeEdit [doc.qt.nokia.com])
and of QLineEdit [doc.qt.nokia.comlatest]

QDate [doc.qt.nokia.com], QDateTime [doc.qt.nokia.com] and QTime [doc.qt.nokia.com] are not QObjects and therefore send no signals at all.

Signal editingFinished() is not used in QStyledItemDelegate to determine if one is done with editing an item in the view.

Why do you set a customized item delegate at all and which standard behavior do you overwrite?

December 9, 2010

Franzk Franzk
Lab Rat
830 posts

xeroblast wrote:
someone in the other forum suggested about editingFinished() signal which works.
That would have been me. It would be nice if you place a link in the QtCentre forum thread to this thread as well.

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

December 10, 2010

xeroblast xeroblast
Lab Rat
91 posts
Franzk wrote:
That would have been me. It would be nice if you place a link in the QtCentre forum thread to this thread as well.

thanx.. http://www.qtcentre.org/threads/36765-QDate-dateChanged()-signal

 
  ‹‹ Overloading signal possible? Or adding new signals to base classes?      QSqlRelationalTableModel and setFilter difficulties - possible bug? ››

You must log in to post a reply. Not a member yet? Register here!