C++ (Qt) tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows); tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
C++ (Qt)void QAbstractItemView::setSelectionBehavior( QAbstractItemView::SelectionBehavior behavior );
C++ (Qt)#define VIA_HACK #ifdef VIA_HACKstatic inline QObject* getSender( QObject* o ){ struct _ObjectP_ : QObject { _ObjectP_( QObject* p = 0 ) : QObject( p ) {} QObject* sender() const { return QObject::sender(); } }; return ( (_ObjectP_*) o )->sender();}#endif // VIA_HACK class SelectionModel : public QItemSelectionModel{public: SelectionModel( QAbstractItemModel* model, QObject* parent ) : QItemSelectionModel( model, parent ) {} void select( const QItemSelection& selection, QItemSelectionModel::SelectionFlags command ) override {#ifdef VIA_HACK if( qobject_cast< QHeaderView* >( getSender( parent() ) ) )#else auto sl = selection.indexes(); if( ( sl.first().row() == sl.last().row() && sl.first().column() == 0 && sl.last().column() == model()->columnCount() - 1 ) || ( sl.first().column() == sl.last().column() && sl.first().row() == 0 && sl.last().row() == model()->rowCount() - 1 ) )#endif QItemSelectionModel::select( selection, command ); }}; SelectionModel selm( tableWidget->model(), tableWidget );tableWidget->setSelectionModel( &selm );
C++ (Qt) struct _ObjectP_ : QObject { _ObjectP_( QObject* p = 0 ) : QObject( p ) {} QObject* sender() const { return QObject::sender(); } };
C++ (Qt)struct _ObjectP_ : public QObject { using QObject::sender; };