qtablewidget.cpp*void QTableWidgetPrivate::setup(){ Q_Q(QTableWidget); // view signals... QObject::connect(q, SIGNAL(doubleClicked(QModelIndex)), q, SLOT(_q_emitItemDoubleClicked(QModelIndex)));...}
void QTableWidgetPrivate::_q_emitItemDoubleClicked(const QModelIndex &index){ Q_Q(QTableWidget); if (QTableWidgetItem *item = model()->item(index)) emit q->itemDoubleClicked(item); emit q->cellDoubleClicked(index.row(), index.column());}
...//Для возможности сортировкиclass CMyTableWidgetItem1 : public QTableWidgetItem{ bool operator<(const QTableWidgetItem &other) const;};...
...CMyTableWidgetItem1 *p_file_name = NULL;p_file_name = (CMyTableWidgetItem1*)new QTableWidgetItem(QString("тут имя файла"));p_file_name->setFlags(Qt::ItemIsSelectable);if(p_file_name) p_tbl->setItem(n_row, 0, p_file_name);...
CMyTableWidgetItem1 *p_file_name = NULL;p_file_name = (CMyTableWidgetItem1*)new QTableWidgetItem(QString("тут имя файла"));p_file_name->setFlags(Qt::ItemIsSelectable);if(p_file_name) p_tbl->setItem(n_row, 0, p_file_name);
CMyTableWidgetItem1 *p_file_name = new CMyTableWidgetItem1(QString("тут имя файла"));p_file_name->setFlags(Qt::ItemIsSelectable);p_tbl->setItem(n_row, 0, p_file_name);
for(int i=0; i < n_row_count; i++){ CMyTableWidgetItem1*p_file_name = NULL; CMyTableWidgetItem1*p_card_number = NULL; CMyTableWidgetItem1*p_lat_number = NULL; CMyTableWidgetItem1*p_kind_crime = NULL; CMyTableWidgetItem1*p_priority = NULL; CMyTableWidgetItem1*p_time = NULL; CMyTableWidgetItem1*p_type = NULL;//имя файла без пути и расширения try { p_file_name = (CMyTableWidgetItem1*)new QTableWidgetItem(QString(local_list.at(i).fileName())); p_file_name->setFlags(Qt::ItemIsSelectable); if(p_file_name) p_tbl->setItem(n_row, 0, p_file_name);// и дальше создание остальных n-айтемов с другими данными текущей строки таблицы... } catch(...) { err_mem(); reject(); }}
QTableWidgetItem1 *p_file_name = NULL;p_file_name = new QTableWidgetItem(QString(...));
CMyTableWidgetItem1 *p_file_name = NULL;p_file_name = new CMyTableWidgetItem1(QString(...));
p_card_number = new CMyTableWidgetItem1();p_tbl->setItem(n_row, 1, p_card_number);...p_card_number->setText(QString(str_val));
CMyTableWidgetItem1 *p_file_name = NULL;p_file_name = new CMyTableWidgetItem1();p_file_name->setText(QString(local_list.at(i).fileName()));p_tbl->setItem(n_row, 0, p_file_name);
bool CMyTableWidgetItem1::operator<(const QTableWidgetItem &other) const{ const QVariant l = data(Qt::DisplayRole), r = other.data(Qt::DisplayRole); switch(l.type()) { case QVariant::Invalid: return (r.type() == QVariant::Invalid); case QVariant::Int: return l.toInt() < r.toInt(); case QVariant::UInt: return l.toUInt() < r.toUInt(); case QVariant::LongLong: return l.toLongLong() < r.toLongLong(); case QVariant::ULongLong: return l.toULongLong() < r.toULongLong(); case QVariant::Double: return l.toDouble() < r.toDouble(); case QVariant::Char: return l.toChar() < r.toChar(); case QVariant::Date: return l.toDate() < r.toDate(); case QVariant::Time: return l.toTime() < r.toTime(); case QVariant::DateTime: return l.toDateTime() < r.toDateTime(); case QVariant::String: default: return l.toString().compare(r.toString(), Qt::CaseSensitive) < 0; } return l.toString() < r.toString();}
if(l.type() != someType) { return QTableWidgetItem::operator<(other); } return result_of_compare_someType;
p_file_name->setFlags(Qt::ItemIsSelectable);
bool QTableWidgetItem::operator<(const QTableWidgetItem &other) const{ const QVariant v1 = data(Qt::DisplayRole), v2 = other.data(Qt::DisplayRole); if (QTableModel::canConvertToDouble(v1) && QTableModel::canConvertToDouble(v2)) return v1.toDouble() < v2.toDouble(); return v1.toString() < v2.toString();}
C++ (Qt) QDateTime dt = QDateTime::currentDateTime(); QDateTime dt2 = QDateTime::currentDateTime().addDays(-3); qDebug()<<dt.toString(Qt::SystemLocaleShortDate)<<dt2.toString(Qt::SystemLocaleShortDate); qDebug()<<QVariant(dt).toString()<<QVariant(dt2).toString(); qDebug()<<(QVariant(dt).toString()<QVariant(dt2).toString());
"06.03.2009 12:39:18" "03.03.2009 12:39:18""2009-03-06T12:39:18" "2009-03-03T12:39:18"false