C++ (Qt)void QAbstractItemModel::sort ( int column, Qt::SortOrder order = Qt::AscendingOrder ) [virtual]
C++ (Qt)bool YourTableWidgetItem::operator< ( const QTableWidgetItem & other ) const{ if( this->column() == 0 && other.column() == 0 ) { if( this->text().contains( "Казахстан" ) ) return true; if( other.text().contains( "Казахстан" ) ) return false; if( this->text().contains( "Россия" ) ) return true; if( other.text().contains( "Россия" ) ) return false; } return this->QTableWidgetItem::operator<( other );}
C++ (Qt)void QTableWidget::setItemPrototype ( const QTableWidgetItem * item )
C++ (Qt)#ifndef ITEM_H#define ITEM_H#include <QTableWidgetItem>#include <QTableWidget> class ItemSort : public QTableWidgetItem{ Q_OBJECTpublic: explicit ItemSort(); ~ItemSort(); // bool operator< ( const QTableWidgetItem & other ) const;} #endif // ITEM_H
C++ (Qt)#include <QTableWidgetItem>#include <QTableWidget>ItemSort(): QTableWidgetItem(""){ }
class ItemSort : public QTableWidgetItem{public: explicit ItemSort(); ~ItemSort(); virtual bool operator< ( const QTableWidgetItem & other ) const;}
ItemSort::ItemSort(): QTableWidgetItem(){}bool ItemSort::operator< ( const QTableWidgetItem & other ) const{ if( this->column() == 0 && other.column() == 0 ) { if( this->text().contains( "Казахстан" ) ) return true; if( other.text().contains( "Казахстан" ) ) return false; if( this->text().contains( "Россия" ) ) return true; if( other.text().contains( "Россия" ) ) return false; } return this->QTableWidgetItem::operator<( other );}
#ifndef ITEM_H#define ITEM_H#include <QTableWidgetItem>#include <QTableWidget>class ItemSort : public QTableWidgetItem{public: ItemSort(QString s); ItemSort(); virtual bool operator< ( const QTableWidgetItem & other ) const;};#endif // ITEM_H
#include "dialog.h"#include "ui_dialog.h"#include "mainwindow.h"#include <QtNetwork\QTcpSocket>#include <QMessageBox>#include "Item.h"#include <QTableWidgetItem>#include <QTableWidget>ItemSort::ItemSort(QString s): QTableWidgetItem(s){}ItemSort::ItemSort(): QTableWidgetItem(){}bool ItemSort::operator< ( const QTableWidgetItem & other ) const{ if( (this->column() == 0 && other.column() == 0) && (this->row() > 0 && other.row() > 0)) { // QMessageBox::information(0,"",""); if( this->text().contains( "Казахстан" ) ) return false; if( other.text().contains( "Казахстан" ) ) return true; if( this->text().contains( "Россия" ) ) return false; if( other.text().contains( "Россия" ) ) return true; } return this->QTableWidgetItem::operator<( other );}