#ifndef LISTWIDGET_H#define LISTWIDGET_H#include <QtGui/QListWidget>class ListWidget : public QListWidget{ Q_OBJECTpublic: ListWidget( QWidget *parent = 0 ); ~ListWidget();private: int centralRow(); void markCentralItem(); void keyPressEvent( QKeyEvent * ); void replaseItem( bool up = true );};#endif // LISTWIDGET_H
#include "listwidget.h"#include <QtGui>ListWidget::ListWidget( QWidget * parent ) : QListWidget( parent ){ QStringList items; items << "0" << "1" << "2" << "3" << "4" << "5" << "6" << "7" << "8" << "9"; addItems( items ); markCentralItem();}ListWidget::~ListWidget(){}int ListWidget::centralRow(){ return ( count() % 2 ) ? count() / 2 : count() / 2 - 1; }void ListWidget::markCentralItem(){ QFont font = item( centralRow() )->font(); font.setPointSize( qApp->font().pointSize() * 2 ); item( centralRow() )->setFont( font ); setCurrentRow( centralRow() );}void ListWidget::replaseItem( bool up ){ if( count() ) { QFont font = item( centralRow() )->font(); font.setPointSize( qApp->font().pointSize() ); item( centralRow() )->setFont( font ); if( up ) insertItem( 0, takeItem( count() - 1 ) ); else insertItem( count(), takeItem( 0 ) ); markCentralItem(); }}void ListWidget::keyPressEvent( QKeyEvent * event ){ if( event->key() == Qt::Key_Up ) replaseItem( true ); if( event->key() == Qt::Key_Down ) replaseItem( false );}
#ifndef LISTWIDGET_H#define LISTWIDGET_H#include <QtGui/QListWidget>class ListWidget : public QListWidget{.........
list_1 = new QListView(this); list_1->setModel(model); list_1->setCurrentIndex(model->index(0, 0)); list_1->setFocusPolicy( Qt::NoFocus ); list_2 = new ListView(this); list_2->setModel(model); list_2->setModelColumn(1); list_2->setRootIndex(model->index(0,0)); connect(list_1, SIGNAL(clicked(const QModelIndex &)), this, SLOT( сhangeItemList_1(const QModelIndex &)));}void MainWindow::changeItemList_1 (const QModelIndex &fld){ list_2->setRootIndex(fld);}