examples/itemviews/frozencolumn/freezetablewidget.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    50       frozenTableView = new QTableView(this);
    50       frozenTableView = new QTableView(this);
    51 
    51 
    52       init();
    52       init();
    53 
    53 
    54       //connect the headers and scrollbars of both tableviews together
    54       //connect the headers and scrollbars of both tableviews together
    55       connect(horizontalHeader(),SIGNAL(sectionResized ( int ,int,int )), this,
    55       connect(horizontalHeader(),SIGNAL(sectionResized(int,int,int)), this,
    56               SLOT(updateSectionWidth(int, int, int)));
    56               SLOT(updateSectionWidth(int,int,int)));
    57       connect(verticalHeader(),SIGNAL(sectionResized ( int ,int,int )), this,
    57       connect(verticalHeader(),SIGNAL(sectionResized(int,int,int)), this,
    58               SLOT(updateSectionHeight(int, int, int)));
    58               SLOT(updateSectionHeight(int,int,int)));
    59 
    59 
    60       connect(frozenTableView->verticalScrollBar(), SIGNAL(valueChanged(int)),
    60       connect(frozenTableView->verticalScrollBar(), SIGNAL(valueChanged(int)),
    61               verticalScrollBar(), SLOT(setValue(int)));
    61               verticalScrollBar(), SLOT(setValue(int)));
    62       connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
    62       connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
    63               frozenTableView->verticalScrollBar(), SLOT(setValue(int)));
    63               frozenTableView->verticalScrollBar(), SLOT(setValue(int)));
    82       viewport()->stackUnder(frozenTableView);
    82       viewport()->stackUnder(frozenTableView);
    83 //! [init part1]
    83 //! [init part1]
    84 
    84 
    85 //! [init part2]
    85 //! [init part2]
    86       frozenTableView->setStyleSheet("QTableView { border: none;"
    86       frozenTableView->setStyleSheet("QTableView { border: none;"
    87                                      "background-color: #8EDE21;}"); //for demo purposes
    87                                      "background-color: #8EDE21;"
       
    88                                      "selection-background-color: #999}"); //for demo purposes
    88       frozenTableView->setSelectionModel(selectionModel());
    89       frozenTableView->setSelectionModel(selectionModel());
    89       for(int col=1; col<model()->columnCount(); col++)
    90       for(int col=1; col<model()->columnCount(); col++)
    90             frozenTableView->setColumnHidden(col, true);
    91             frozenTableView->setColumnHidden(col, true);
    91 
    92 
    92       frozenTableView->setColumnWidth(0, columnWidth(0) );
    93       frozenTableView->setColumnWidth(0, columnWidth(0) );
   144       }
   145       }
   145       return current;
   146       return current;
   146 }
   147 }
   147 //! [navigate]
   148 //! [navigate]
   148 
   149 
       
   150 void FreezeTableWidget::scrollTo (const QModelIndex & index, ScrollHint hint){
       
   151     if(index.column()>0)
       
   152         QTableView::scrollTo(index, hint);
       
   153 }
       
   154 
       
   155 
   149 
   156 
   150 //! [geometry]
   157 //! [geometry]
   151 void FreezeTableWidget::updateFrozenTableGeometry()
   158 void FreezeTableWidget::updateFrozenTableGeometry()
   152 {
   159 {
   153       frozenTableView->setGeometry( verticalHeader()->width()+frameWidth(),
   160       frozenTableView->setGeometry( verticalHeader()->width()+frameWidth(),