Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: How To Apply Scroll Only for few columns of QTableview

  1. #1
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default How To Apply Scroll Only for few columns of QTableview

    Hi ,

    I have to apply scroll for few columns in QTableView , I want to except some columns that are in one corner of QTableview , means i would like to left scroll from first 3 columns . Could anyone help us . I need it so badly ...

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How To Apply Scroll Only for few columns of QTableview

    You cannot do this with a single function call. Take a look at the Frozen Column example for a way to "fake" it.

  3. #3
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Apply Scroll Only for few columns of QTableview

    I tried same code but the scroll applied for all columns .


    Added after 1 27 minutes:


    I tried with two QTableviews , I was hide columns which are not want to freeze in 1st tableview , and in second table view I was hide freeze columns except all .
    I attached both tableviews into QHBoxLayout . and I applied horizontal scroll only for 2nd tableview . But , My Problem is , QHBoxLayout split the space for two tableviews equally , I set SizePolicy Preferred , But still i have some space between two tableviews , How can I Manage this .
    I am following this way because , I have added The above layout into QVBoxLayout , and second widget in this QVBoxLayout as Onother Tableview the Horizontal scroll of above table view depends on below scroll . I was Hide the above tableview scroll and when i move bottom tableview scroll am moving above tableview columns . So Please anyone Help Us .
    Last edited by RameshNani; 16th December 2014 at 11:25.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How To Apply Scroll Only for few columns of QTableview

    So your problem is really, "How do I fix the width of a table widget in a horizontal box layout?"
    What have you actually tried? What does your code look like? What does it do?

    BTW, it sounds like putting all the widgets in a grid layout would work well for you.

  5. #5
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Apply Scroll Only for few columns of QTableview

    I am doing like below for freeze some columns from start ,

    QTableview *childview = new QTableview();
    childview ->horizantalscrollbar()->hide()
    QTableview *FrozenchildView= new QTableView();
    FrozenchildView->horizantalscrollbar()->hide();
    FrozenchildView->verticalscrollbar()->hide();
    FrozenchildView->setsizepolicy(QSizepolicy::Preffered,QSizepolicy: :Minimum)
    QTableView * sumView= new QTableView();
    QTableView *FrozenSumView=new QTableView();
    model1=new qsqlquerymodel();
    model2=new qsqlquerymodel();
    QSortfilterproxymodel *proxy=new qsortfilterproxymodel();
    model1->setQuery(sql);
    proxy->setsourcemodel(model1);
    childview->setmodel(proxy);
    FrozenchildView->setmodel(proxy);
    model2->setquery(sql);
    qsortfilterproxymodel *sumproxy=new qsortfilterproxymodel();
    sumproxy->setsourcemodel(model2);
    sumView->setmodel(sumproxy);
    FrozenSumView>setmodel(sumproxy);
    QHBoxLayout *hlout = new QHBoxLayout();
    hlout ->addwidget(FrozenchildView);
    hlout ->addwidget(childView);
    QHboxLayout *hloutsum = new QHboxLayout();
    hloutsum->addwidget(FrozenSumView);
    hloutsum->addwidget(sumView);
    QVBoxlayout *vlot = new QVBoxlayout();
    vlot ->addLayout(hlout);
    vlot ->addLayout(hloutsum);
    connect(sumView->horizontalScrollBar(), SIGNAL(valueChanged(int)),childView->horizontalScrollBar(), SLOT(setValue(int)));
    connect(childView->verticalScrollBar(), SIGNAL(valueChanged(int)),FrozenchildView->verticalScrollBar(), SLOT(setValue(int)));
    //In FrozenchildView I am showing only Frozen Columns, Remaining all columns are Hiden , and in childview am hiding FrozenColumns and showing all other columns.
    //I was applied same for sumview,frozensumview .

    These are my Functionalities , But doing like above the the layout had some space between two tableviews . Could any one help us .image.jpg
    I Attached Screen shot , Please find it .

  6. #6
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Apply Scroll Only for few columns of QTableview

    If any Questions on above context , Please query to me , am doing like above .

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How To Apply Scroll Only for few columns of QTableview

    The spacing between widgets in a horizontal layout is contolled by QLayout::setSpacing() and around the outside of the layout by QLayout::setContentsMargins()

  8. #8
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Apply Scroll Only for few columns of QTableview

    We only able to apply setspacing for each widget in a layout right right ? Is there any way to apply directly on layout to set space between widgets with in that layout ?

  9. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How To Apply Scroll Only for few columns of QTableview

    Quote Originally Posted by RameshNani View Post
    Is there any way to apply directly on layout to set space between widgets with in that layout ?
    Maybe you should read comment #7 again.

    Cheers,
    _

  10. #10
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Apply Scroll Only for few columns of QTableview

    Hi ,

    Now am able to freez columns , But i have one issue , that is when i use customized header the columns are freezing but the headers are moving . could any one help me . i need it very badly .

    am using customized tableview frozentablewidget example code .

  11. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How To Apply Scroll Only for few columns of QTableview

    Since the Frozen Column example headers work in the expected way you should probably study that.

  12. #12
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Apply Scroll Only for few columns of QTableview

    HI , The frozentableview columns are frozen , but my cusom header override frozentableview header section , thats why the columns are moving , but i don't have any idea to distinguish frozentableview and custom header sections . the custom header painting section every time .

  13. #13
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How To Apply Scroll Only for few columns of QTableview

    The Frozen Column example does just that: the headers of the frozen column do not move when the rest of the table is scrolled right. Simply set your custom QHeaderView as the horizontal header of both table views.

  14. #14
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Apply Scroll Only for few columns of QTableview

    Hi , In my custom Header i am painting the sections .

    for the frozen column also we are getting header column , but this header column override with customheaderview column , so it's moving , is there any way to prevent the painting perticular section in QHeaderView . when i pass same customheader to frozen table widget and when i use this one for frozentableview the maintableview columns also hiding . so other than this i created new custom header object and given for frozen tableview also but i have same issue . i need it very urgently . could any one help me .

    Hi Could you please review my code
    Mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <MySortfilterProxyModel.h>
    6.  
    7. namespace Ui {
    8. class MainWindow;
    9. }
    10.  
    11. class MainWindow : public QMainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18. MySortFilterProxyModel * proxy;
    19.  
    20. public slots :
    21. void setFilterColumn(int);
    22. void setFilterRegExpxx(int,QString);
    23. void setFilterRegExpU(int,QString);
    24.  
    25. private:
    26. Ui::MainWindow *ui;
    27. };
    28.  
    29. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include "freezetablewidget.h"
    4. #include <QtGui>
    5. #include "QSqlDatabase"
    6. #include <QSqlQueryModel>
    7. #include <QSqlTableModel>
    8. #include <MySortfilterProxyModel.h>
    9. #include <CustomHeader.h>
    10. #include <QDir>
    11.  
    12. MainWindow::MainWindow(QWidget *parent) :
    13. QMainWindow(parent),
    14. ui(new Ui::MainWindow)
    15. {
    16. ui->setupUi(this);
    17. QDir *dir = new QDir();
    18. qDebug()<<"Current Path :"<<dir->currentPath();
    19.  
    20. //QDir *dir = new QDir();
    21. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    22. //QDir *dir = new QDir();
    23. // db.setDatabaseName("F:/sqlite/test.db");
    24. //QDir *dir = new QDir();
    25. db.setDatabaseName(dir->currentPath()+"/DataBase/test.db");
    26. db.open();
    27. // QSqlTableModel *model = new QSqlTableModel(this,db);
    28. // QAbstractTableModel *model = new QAbstractTableModel();
    29. QSqlQueryModel *modelsum = new QSqlQueryModel();
    30. proxy = new MySortFilterProxyModel();
    31. proxy->setSourceModel(model);
    32. CustomHeader *m_header = new CustomHeader(Qt::Horizontal);
    33.  
    34. FreezeTableWidget *tableView = new FreezeTableWidget(proxy,m_header);
    35. tableView->setHorizontalHeader(m_header);
    36. // tableView->horizontalHeader()->hide();
    37. // tableView->setColumnHidden(0, true);
    38. CustomHeader *sumHeader = new CustomHeader(Qt::Horizontal);
    39. FreezeTableWidget *tableViewsum = new FreezeTableWidget(modelsum,sumHeader);
    40. tableViewsum->horizontalHeader()->hide();
    41. tableViewsum->horizantalHeader_Hide();
    42.  
    43.  
    44.  
    45. connect(m_header, SIGNAL(searchString(int,QString)), this, SLOT(setFilterRegExpxx(int,QString)));
    46. connect(m_header, SIGNAL(indexOfColumn(int)), this, SLOT(setFilterColumn(int)));
    47. //SUPRAJA JAN 20
    48. connect(m_header, SIGNAL(unfilter(int,QString)), this, SLOT(setFilterRegExpU(int,QString)));
    49. /*
    50.   QHeaderView *m_header = new CustomHeader(Qt::Horizontal);
    51.   childView->setHorizontalHeader(m_header);
    52.   connect(m_header, SIGNAL(searchString(int,QString)), this, SLOT(setFilterRegExpxx(int,QString)));
    53.   connect(m_header, SIGNAL(indexOfColumn(int)), this, SLOT(setFilterColumn(int)));
    54.   //SUPRAJA JAN 20
    55.   connect(m_header, SIGNAL(unfilter(int,QString)), this, SLOT(setFilterRegExpU(int,QString)));
    56.   */
    57. model->setQuery("select symbol,security,quantity,symbol as M_Symbol,security as M_Security,quantity as M_Quantity,symbol as R_Symbol,security as R_Security,quantity as R_Quantity from portfolio",db);
    58. // QSqlQuery query="select symbol,security,quantity,symbol as M_Symbol,security as M_Security,quantity as M_Quantity,symbol as R_Symbol,security as R_Security,quantity as R_Quantity from portfolio";
    59. // model->setQuery(query);
    60. modelsum->setQuery("select symbol,security,quantity,symbol as M_Symbol,security as M_Security,quantity as M_Quantity,symbol as R_Symbol,security as R_Security,quantity as R_Quantity from portfolio",db);
    61.  
    62. //
    63. // connect(tableViewsum,SIGNAL(tableViewsum->horizontalHeader()->scroll()),tableView,);
    64. connect(tableViewsum->horizontalScrollBar(), SIGNAL(valueChanged(int)),tableView->horizontalScrollBar(), SLOT(setValue(int)));
    65. tableView->setModel(proxy);
    66. // tableView->setColumnHidden(0, true);
    67. tableViewsum->setModel(modelsum);
    68. QWidget *centralwidget = new QWidget(this);
    69. this->setCentralWidget( centralwidget );
    70. QVBoxLayout *layout = new QVBoxLayout(centralwidget);
    71. layout->addWidget(tableView);
    72. layout->addWidget(tableViewsum);
    73. centralwidget->setLayout(layout);
    74. // layout->
    75.  
    76. }
    77.  
    78. MainWindow::~MainWindow()
    79. {
    80. delete ui;
    81. }
    82.  
    83. void MainWindow::setFilterRegExpxx(int index,QString ss)
    84. {
    85. qDebug()<<"setfilter reg expression";
    86. // if(proxy->multifilter.contains(index))
    87. // proxy->multifilter[index]=ss;
    88. // else
    89. // proxy->multifilter.insert(index,ss);
    90. std::string sss=ss.toStdString();
    91. proxy->multifilter[index]=sss;
    92. proxy->setFilterRegExp(ss);
    93. }
    94. void MainWindow::setFilterRegExpU(int index,QString ss)
    95. {
    96. //if(proxy->multifilter.find(index)!=-1)
    97. {
    98. // proxy->multifilter.remove(index);
    99. qDebug()<<"Erase From Map :"<<index;
    100. proxy->multifilter.erase(index);
    101. proxy->setFilterRegExp(ss);
    102. }
    103. }
    104. void MainWindow::setFilterColumn(int i)
    105. {
    106.  
    107. qDebug()<<"SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS SetFilter Key column";
    108. proxy->setFilterKeyColumn(i);
    109. // proxyModel->sort(i);
    110.  
    111. }
    To copy to clipboard, switch view to plain text mode 


    Added after 4 minutes:


    CustomHeader.h
    Qt Code:
    1. #ifndef CUSTOMHEADER_H
    2. #define CUSTOMHEADER_H
    3.  
    4. #include <QHeaderView>
    5. #include <QtGui>
    6. //#include "HideColumnsCombo.h"
    7. class CustomHeader : public QHeaderView
    8. {
    9. Q_OBJECT
    10. public:
    11. CustomHeader(Qt::Orientation orientation, QWidget * parent = 0);
    12. bool sflag,icon;
    13. QVector<int> filterIndex;
    14. void testfun();
    15.  
    16. protected:
    17. void mousePressEvent(QMouseEvent * event);
    18. void mouseMoveEvent(QMouseEvent * event);
    19. void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
    20.  
    21. QRect sectionRect(int logicalIndex) const;
    22. QRect buttonMenuRect(int logicalIndex) const;
    23. QRect prevRect(int logicalIndex) const;
    24. QRect nextRect(int logicalIndex) const;
    25.  
    26. void drawMenuButton(QPainter *painter, int logicalIndex, bool enabled) const;
    27. void drawMenuButton1(QPainter *painter, int logicalIndex, bool enabled) const;
    28. void drawPrevButton(QPainter *painter, int logicalIndex) const;
    29. void drawNextButton(QPainter *painter, int logicalIndex) const;
    30. public slots:
    31. void changedData(QString);
    32.  
    33. //void unfilter(QString);
    34. void copy1();
    35. void slot_changed(const QModelIndex& , const QModelIndex& );
    36. void UnfilterColumn() ;
    37.  
    38. signals:
    39. void searchString(int,QString);
    40. void unfilter(int,QString);
    41. void indexOfColumn(int);
    42. private:
    43. mutable bool mouseoverflg;
    44. //HideColumnsCombo *list;
    45. QComboBox *comboBox;
    46. QVector<QStandardItem*> Items;
    47.  
    48. QMap<QString,int> m_hideColumns;
    49. QWidgetAction *hideAction;
    50.  
    51. };
    52.  
    53. #endif
    To copy to clipboard, switch view to plain text mode 

    CustomHeader.cpp

    Qt Code:
    1. #include <QPainter>
    2. #include <QCursor>
    3. #include <QHoverEvent>
    4. #include <QMenu>
    5. //nclude "CheckBoxList.h"
    6. #include "CustomHeader.h"
    7. int disableflag=0;
    8. QModelIndex d_index;
    9. int m_index = 0;
    10. CustomHeader::CustomHeader(Qt::Orientation orientation, QWidget * parent)
    11. : QHeaderView(orientation, parent),mouseoverflg(false)
    12. {
    13. // Required to refresh button menu when the mouse leave the header.
    14. //setAttribute(Qt::WA_Hover, true);
    15. qDebug()<<"IN CUSTOM HEADER";
    16. icon=false;
    17. }
    18.  
    19. void CustomHeader ::testfun()
    20. {
    21. qDebug()<<"FOR UNFILTER ICONNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN";
    22. filterIndex.remove(0,filterIndex.size());
    23. }
    24.  
    25. void CustomHeader::UnfilterColumn()
    26. {
    27. qDebug()<<"In Unfilter";
    28. QString un="";
    29. qDebug()<<"UNFILTERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR"<<un;
    30. //emit unfilter(un);
    31. //qDebug()<<"UNFILTERRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR1111111111111111111111111111111111"<<un;
    32. int c=filterIndex.size();
    33. filterIndex.remove(m_index);
    34. /*for(int i=0;i<filterIndex.size();i++)
    35. {
    36.   qDebug()<<"In Unfilter"<<i<<filterIndex.size();
    37. // if(filterIndex.at(i)==logicalIndex)
    38.   int j=filterIndex[i];
    39.   qDebug()<<"j"<<j;
    40. //SCH For removing filter specific column if(m_index==j)
    41.   filterIndex.remove(i);
    42.   qDebug()<<"In Unfilter1111"<<filterIndex.size();
    43.  
    44. }*/
    45. //emit unfilter(un);
    46. emit unfilter(m_index,un);
    47.  
    48. }
    49. void CustomHeader::mousePressEvent ( QMouseEvent * event )
    50. {
    51. // qDebug()<<"mouse press beginssssssssssssssssssssssssssssssssssssssssss";
    52. QHeaderView::mousePressEvent(event);
    53. Items.clear();
    54. comboBox=new QComboBox();
    55. comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    56. Model = new QStandardItemModel;
    57. qDebug()<<" In Custom Header";
    58. for(int i =0; i<model()->columnCount();i++)
    59. {
    60. QString columnName = model()->headerData( i, Qt::Horizontal ).toString();
    61. m_hideColumns[columnName]=i;
    62. Item1 = new QStandardItem;
    63. Item1->setText(columnName);
    64. Item1->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
    65. if(isSectionHidden (i))
    66. Item1->setData(Qt::Checked, Qt::CheckStateRole);
    67. else
    68. Item1->setData(Qt::Unchecked, Qt::CheckStateRole);
    69. Model->insertRow(i,Item1);
    70.  
    71. Items.push_back(Item1);
    72.  
    73. }
    74.  
    75. connect(Model, SIGNAL(dataChanged ( const QModelIndex&, const QModelIndex&)), this, SLOT(slot_changed(const QModelIndex&, const QModelIndex&)));
    76. comboBox->setModel(Model);
    77. int logicalIndex = logicalIndexAt(event->pos());
    78. m_index = logicalIndex;
    79. // qDebug()<<"LOGICAL INDEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"<<logicalIndex;
    80.  
    81. // qDebug()<<" emit indexOfColumn(logicalIndex);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"<<event->pos();
    82. if (buttonMenuRect(logicalIndex).contains(event->pos())) {
    83. QMenu menu(this);
    84. emit indexOfColumn(logicalIndex);
    85. // QAction *hideCol = menu.addAction("Hide column");
    86. //QAction *sortAZ = menu.addAction("Sort sheet A->Z");
    87. //QAction *sortZA = menu.addAction("Sort sheet Z->A");
    88. QLineEdit *lineEdit = new QLineEdit(&menu);
    89.  
    90. lineEdit ->setStyleSheet("background-color: white;");
    91.  
    92. QWidgetAction *widgetAction = new QWidgetAction(&menu);
    93. widgetAction->setDefaultWidget(lineEdit);
    94. hideAction = new QWidgetAction(&menu);
    95. hideAction->setDefaultWidget(comboBox);
    96. connect(lineEdit,SIGNAL(textChanged(QString)),this,SLOT(changedData(QString)));
    97. QMenu *menu1 = new QMenu(QString("%1").arg("Search"),this);
    98. QAction *unfilter = new QAction("UnFilter",this);
    99. menu1->addAction(widgetAction);
    100. // connect(menu1, SIGNAL(triggered(menu1)), this, SLOT(copy1()));
    101. menu.addMenu(menu1);
    102. menu.addAction(unfilter);
    103. QMenu *hidemenu = new QMenu(QString("%1").arg("Hide Columns"),this);
    104. hidemenu->addAction(hideAction);
    105. menu.addMenu(hidemenu);
    106. connect(unfilter,SIGNAL(triggered()),this,SLOT(UnfilterColumn())) ;
    107. //menu.addAction(hideCol);
    108.  
    109. // Disable hide column if only one column remains. Otherwise
    110. // the gui is no more available to show them back.
    111. // hideCol->setEnabled(hiddenSectionCount() < count() - 1);
    112.  
    113. QAction *res = menu.exec(mapToGlobal(event->pos()));
    114.  
    115. /*if (res == hideCol) {
    116.   hideSection(logicalIndex);
    117.   updateSection(logicalIndex-1);
    118.   } if (res == sortAZ)
    119.   static_cast<QSortFilterProxyModel*>(model())->sourceModel()->sort(logicalIndex, Qt::AscendingOrder);
    120.   if (res == sortZA)
    121.   static_cast<QSortFilterProxyModel*>(model())->sourceModel()->sort(logicalIndex, Qt::DescendingOrder);
    122.  
    123.   if (res == sortAZ)
    124.   (model())->sort(logicalIndex, Qt::AscendingOrder);
    125.   if (res == sortZA)
    126.   (model())->sort(logicalIndex, Qt::DescendingOrder);
    127. */
    128.  
    129.  
    130.  
    131.  
    132.  
    133. }
    134.  
    135. // Catch previous arrow mouse click.
    136. if (prevRect(logicalIndex).contains(event->pos())) {
    137. showSection(logicalIndex - 1);
    138. updateSection(logicalIndex - 2);
    139. }
    140.  
    141. // Catch next arrow mouse click.
    142. if (nextRect(logicalIndex).contains(event->pos())) {
    143. showSection(logicalIndex + 1);
    144. updateSection(logicalIndex + 2);
    145. }
    146. //qDebug()<<"Mouse press closeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
    147. }
    148.  
    149.  
    150. void CustomHeader::slot_changed(const QModelIndex& topLeft, const QModelIndex& bottomRight)
    151. {
    152. // qDebug()<<"slottttttttttttttttttt changed";
    153. QStandardItem* item = Items[topLeft.row()];
    154. if(item->checkState() == Qt::Unchecked)
    155. {
    156.  
    157. showSection(logicalIndex(m_hideColumns[bottomRight.data(Qt::DisplayRole).toString()]));
    158. updateSection(logicalIndex(m_hideColumns[bottomRight.data(Qt::DisplayRole).toString()])-1);
    159.  
    160.  
    161. //qDebug() << "Uncheckedddddddddddddddddddddddddddddddddddddddddddddddddddddddddd!" ;
    162. }
    163. else if(item->checkState() == Qt::Checked)
    164. {
    165. hideSection(logicalIndex(m_hideColumns[bottomRight.data(Qt::DisplayRole).toString()]));
    166. updateSection(logicalIndex(m_hideColumns[bottomRight.data(Qt::DisplayRole).toString()])-1);
    167. qDebug()<<topLeft.data(Qt::DisplayRole)<<bottomRight.data(Qt::DisplayRole);
    168.  
    169. // qDebug() << "Checkeddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd!";
    170. }
    171.  
    172. }
    173.  
    174. void CustomHeader::copy1()
    175. {
    176. //qDebug()<<"COPY!!!!!!!!!!!!!!!!!!for searchhhhhhhhhhhhhhhhhhhhhh";
    177.  
    178. }
    179.  
    180. void CustomHeader::mouseMoveEvent(QMouseEvent * event)
    181. {
    182. qDebug()<<"mouse moveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee event";
    183. QHeaderView::mouseMoveEvent(event);
    184. mouseoverflg=true;
    185. // Required to refresh the button menu enable/disable state.
    186. int logicalIndex = logicalIndexAt(event->pos());
    187. updateSection(logicalIndex);
    188. }
    To copy to clipboard, switch view to plain text mode 


    Added after 26 minutes:


    Qt Code:
    1. void CustomHeader::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
    2. {
    3. // qDebug()<<"paint";
    4. //QHeaderView::paintSection(painter, rect, logicalIndex);
    5.  
    6. // if (!rect.isValid() || isSortIndicatorShown())
    7. // return;
    8. // qDebug()<<"Paint Section"<<logicalIndex;
    9. // if(logicalIndex=0)
    10. // return;
    11. if (!rect.isValid())
    12. return;
    13. QPoint pos = mapFromGlobal(QCursor::pos());
    14.  
    15. if (rect.contains(pos) ) {
    16. // const_cast<CustomHeader*>(this)->setSortIndicatorShown(true);
    17. painter->save();
    18. //const_cast<CustomHeader*>(this)->setSortIndicatorShown(true);
    19.  
    20. QHeaderView::paintSection(painter, rect, logicalIndex);
    21. //const_cast<CustomHeader*>(this)->setSortIndicatorShown(false);
    22.  
    23. painter->restore();
    24. if(filterIndex.contains(logicalIndex))
    25. {
    26. // qDebug()<<"drawMenuButton1 "<<"logicalIndex"<<logicalIndex;
    27. drawMenuButton1(painter, logicalIndex, 1);
    28. }
    29. else
    30. {
    31. drawMenuButton(painter, logicalIndex, buttonMenuRect(logicalIndex).contains(pos));
    32. }
    33. if (isSectionHidden(logicalIndex - 1)) {
    34. drawPrevButton(painter, logicalIndex);
    35. }
    36. if (isSectionHidden(logicalIndex + 1)) {
    37. drawNextButton(painter, logicalIndex);
    38. }
    39. }
    40. else
    41. {
    42. if(filterIndex.contains(logicalIndex))
    43. {
    44. QString columnName = model()->headerData( logicalIndex, Qt::Horizontal ).toString();
    45. qDebug()<<"columnName"<<columnName;
    46.  
    47. //painter->drawText(rect,columnName);
    48. painter->drawText(rect,Qt::AlignCenter,columnName);
    49.  
    50. QRect brect = buttonMenuRect(logicalIndex);
    51. painter->setPen(Qt::white);
    52. //painter->setBrush(QColor(46,92,127));
    53. painter->setBrush(QColor(176,196,222));
    54. //painter->setBrush(Qt::cyan);
    55.  
    56. painter->setPen(Qt::black);
    57. painter->drawRect(brect);
    58. //painter->setPen(Qt::black);
    59. painter->drawLine(brect.left()+3, brect.top()+5, brect.right()-3, brect.top()+5);
    60. painter->drawLine(brect.left()+4, brect.top()+6, brect.right()-4, brect.top()+6);
    61. painter->drawLine(brect.left()+5, brect.top()+7, brect.right()-5, brect.top()+7);
    62. painter->drawPoint(brect.left()+6, brect.top()+8);
    63. painter->save();
    64. }
    65. else
    66. {
    67. // qDebug()<<visualIndexAt(logicalIndex)<<QHeaderView::logicalIndex ( 0 );
    68.  
    69.  
    70. // qDebug()<<"logicalIndexxxxxyyyy"<<logicalIndex;
    71. QHeaderView::paintSection(painter, rect, logicalIndex);
    72.  
    73. }
    74. }
    75. mouseoverflg=false;
    76. return;
    77. }
    78.  
    79. QRect CustomHeader::sectionRect(int logicalIndex) const
    80. {
    81. return QRect(sectionViewportPosition(logicalIndex), 0, sectionSize(logicalIndex), height());
    82. }
    83.  
    84. QRect CustomHeader::buttonMenuRect(int logicalIndex) const
    85. {
    86. QRect sr = sectionRect(logicalIndex);
    87.  
    88. return QRect(sr.right() - 5 - 13, sr.center().y() - 6, 13, 13);
    89. }
    90.  
    91. QRect CustomHeader::prevRect(int logicalIndex) const
    92. {
    93. if (isSectionHidden(logicalIndex))
    94. return QRect();
    95.  
    96. QRect sr = sectionRect(logicalIndex);
    97.  
    98. return QRect(sr.left() + 1, sr.center().y() - 6, 13, 13);
    99. }
    100.  
    101. QRect CustomHeader::nextRect(int logicalIndex) const
    102. {
    103. if (isSectionHidden(logicalIndex))
    104. return QRect();
    105.  
    106. QRect sr = sectionRect(logicalIndex);
    107.  
    108. return QRect(sr.right() - 13, sr.center().y() - 6, 13, 13);
    109. }
    110.  
    111. void CustomHeader::drawMenuButton1(QPainter *painter, int logicalIndex, bool enabled) const
    112. {
    113. int x = logicalIndex;
    114. // storeindex.push_back(x);
    115. // storeindex
    116. QRect brect = buttonMenuRect(logicalIndex);
    117. painter->setPen(enabled ? QColor(186,186,186) : QColor(223, 223, 223));
    118. // painter->setBrush(QColor(646,646,646));
    119. // painter->setBrush(Qt::cyan);
    120. //painter->setBrush(QColor(46,92,127));
    121. painter->setBrush(QColor(176,196,222));
    122.  
    123. painter->drawRect(brect.adjusted(0,0,-1,-1));
    124. // painter->drawRect(brect);
    125. painter->setPen(enabled ? QColor(71,71,71) : QColor(193, 193, 193));
    126. painter->drawLine(brect.left()+3, brect.top()+5, brect.right()-3, brect.top()+5);
    127. painter->drawLine(brect.left()+4, brect.top()+6, brect.right()-4, brect.top()+6);
    128. painter->drawLine(brect.left()+5, brect.top()+7, brect.right()-5, brect.top()+7);
    129. painter->drawPoint(brect.left()+6, brect.top()+8);
    130. painter->save();
    131. qDebug()<<"drawMenuButtonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn1111111111111111111111111"<<logicalIndex;
    132. }
    133.  
    134. void CustomHeader::drawMenuButton(QPainter *painter, int logicalIndex, bool enabled) const
    135. {
    136. QRect brect = buttonMenuRect(logicalIndex);
    137. painter->setPen(enabled ? QColor(186,186,186) : QColor(223, 223, 223));
    138. painter->setBrush(QColor(246,246,246));
    139. painter->drawRect(brect.adjusted(0,0,-1,-1));
    140. painter->setPen(enabled ? QColor(71,71,71) : QColor(193, 193, 193));
    141. painter->drawLine(brect.left()+3, brect.top()+5, brect.right()-3, brect.top()+5);
    142. painter->drawLine(brect.left()+4, brect.top()+6, brect.right()-4, brect.top()+6);
    143. painter->drawLine(brect.left()+5, brect.top()+7, brect.right()-5, brect.top()+7);
    144. painter->drawPoint(brect.left()+6, brect.top()+8);
    145. }
    146.  
    147. void CustomHeader::drawPrevButton(QPainter *painter, int logicalIndex) const
    148. {
    149. QRect rect = prevRect(logicalIndex);
    150. painter->setPen(QColor(71,71,71));
    151. painter->drawLine(rect.left()+1, rect.center().y() - 3, rect.left()+1, rect.center().y() + 3);
    152. painter->drawLine(rect.left()+2, rect.center().y() - 2, rect.left()+2, rect.center().y() + 2);
    153. painter->drawLine(rect.left()+3, rect.center().y() - 1, rect.left()+3, rect.center().y() + 1);
    154. painter->drawPoint(rect.left()+4, rect.center().y());
    155. }
    156.  
    157. void CustomHeader::drawNextButton(QPainter *painter, int logicalIndex) const
    158. {
    159. QRect rect = nextRect(logicalIndex);
    160. painter->setPen(QColor(71,71,71));
    161. painter->drawLine(rect.right()-2, rect.center().y() - 3, rect.right()-2, rect.center().y() + 3);
    162. painter->drawLine(rect.right()-3, rect.center().y() - 2, rect.right()-3, rect.center().y() + 2);
    163. painter->drawLine(rect.right()-4, rect.center().y() - 1, rect.right()-4, rect.center().y() + 1);
    164. painter->drawPoint(rect.right()-5, rect.center().y());
    165. }
    166. void CustomHeader::changedData(QString s)
    167. {
    168.  
    169. if(s!="")
    170. {
    171. icon=true;
    172. //QStandardItem* pi = new QStandardItem(QIcon("./images/ceditor.png"));
    173. //qDebug()<<"changed dataaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    174. if(!filterIndex.contains(m_index))
    175. filterIndex.push_back( m_index);
    176. emit searchString(m_index,s);
    177. sflag=true;
    178. s="";
    179. }
    180. }
    To copy to clipboard, switch view to plain text mode 

    FrozenTableWidget.h
    Qt Code:
    1. /****************************************************************************
    2.  **
    3.  ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    4.  ** All rights reserved.
    5.  ** Contact: Nokia Corporation (qt-info@nokia.com)
    6.  **
    7.  ** This file is part of the examples of the Qt Toolkit.
    8.  **
    9.  ** $QT_BEGIN_LICENSE:LGPL$
    10.  ** Commercial Usage
    11.  ** Licensees holding valid Qt Commercial licenses may use this file in
    12.  ** accordance with the Qt Commercial License Agreement provided with the
    13.  ** Software or, alternatively, in accordance with the terms contained in
    14.  ** a written agreement between you and Nokia.
    15.  **
    16.  ** GNU Lesser General Public License Usage
    17.  ** Alternatively, this file may be used under the terms of the GNU Lesser
    18.  ** General Public License version 2.1 as published by the Free Software
    19.  ** Foundation and appearing in the file LICENSE.LGPL included in the
    20.  ** packaging of this file. Please review the following information to
    21.  ** ensure the GNU Lesser General Public License version 2.1 requirements
    22.  ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    23.  **
    24.  ** In addition, as a special exception, Nokia gives you certain additional
    25.  ** rights. These rights are described in the Nokia Qt LGPL Exception
    26.  ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    27.  **
    28.  ** GNU General Public License Usage
    29.  ** Alternatively, this file may be used under the terms of the GNU
    30.  ** General Public License version 3.0 as published by the Free Software
    31.  ** Foundation and appearing in the file LICENSE.GPL included in the
    32.  ** packaging of this file. Please review the following information to
    33.  ** ensure the GNU General Public License version 3.0 requirements will be
    34.  ** met: http://www.gnu.org/copyleft/gpl.html.
    35.  **
    36.  ** If you have questions regarding the use of this file, please contact
    37.  ** Nokia at qt-info@nokia.com.
    38.  ** $QT_END_LICENSE$
    39.  **
    40.  ****************************************************************************/
    41.  
    42. #ifndef FREEZETABLEWIDGET_H
    43. #define FREEZETABLEWIDGET_H
    44. #include <CustomHeader.h>
    45.  
    46. #include <QTableView>
    47.  
    48. class FreezeTableWidget : public QTableView {
    49. Q_OBJECT
    50.  
    51. public:
    52. FreezeTableWidget(QAbstractItemModel * model,CustomHeader *m_headerN );
    53. ~FreezeTableWidget();
    54. void horizantalHeader_Hide();
    55. CustomHeader *m_header;
    56. CustomHeader *m_header1;
    57.  
    58. protected:
    59. virtual void resizeEvent(QResizeEvent *event);
    60. virtual QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers);
    61. void scrollTo (const QModelIndex & index, ScrollHint hint = EnsureVisible);
    62.  
    63.  
    64. private:
    65. QTableView *frozenTableView;
    66. void init();
    67. void updateFrozenTableGeometry();
    68.  
    69. private slots:
    70. void updateSectionWidth(int logicalIndex,int, int newSize);
    71. void updateSectionHeight(int logicalIndex, int, int newSize);
    72.  
    73. };
    74. #endif
    To copy to clipboard, switch view to plain text mode 

    FrozenTableWidget.cpp

    Qt Code:
    1. /****************************************************************************
    2.  **
    3.  ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    4.  ** All rights reserved.
    5.  ** Contact: Nokia Corporation (qt-info@nokia.com)
    6.  **
    7.  ** This file is part of the examples of the Qt Toolkit.
    8.  **
    9.  ** $QT_BEGIN_LICENSE:LGPL$
    10.  ** Commercial Usage
    11.  ** Licensees holding valid Qt Commercial licenses may use this file in
    12.  ** accordance with the Qt Commercial License Agreement provided with the
    13.  ** Software or, alternatively, in accordance with the terms contained in
    14.  ** a written agreement between you and Nokia.
    15.  **
    16.  ** GNU Lesser General Public License Usage
    17.  ** Alternatively, this file may be used under the terms of the GNU Lesser
    18.  ** General Public License version 2.1 as published by the Free Software
    19.  ** Foundation and appearing in the file LICENSE.LGPL included in the
    20.  ** packaging of this file. Please review the following information to
    21.  ** ensure the GNU Lesser General Public License version 2.1 requirements
    22.  ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    23.  **
    24.  ** In addition, as a special exception, Nokia gives you certain additional
    25.  ** rights. These rights are described in the Nokia Qt LGPL Exception
    26.  ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    27.  **
    28.  ** GNU General Public License Usage
    29.  ** Alternatively, this file may be used under the terms of the GNU
    30.  ** General Public License version 3.0 as published by the Free Software
    31.  ** Foundation and appearing in the file LICENSE.GPL included in the
    32.  ** packaging of this file. Please review the following information to
    33.  ** ensure the GNU General Public License version 3.0 requirements will be
    34.  ** met: http://www.gnu.org/copyleft/gpl.html.
    35.  **
    36.  ** If you have questions regarding the use of this file, please contact
    37.  ** Nokia at qt-info@nokia.com.
    38.  ** $QT_END_LICENSE$
    39.  **
    40.  ****************************************************************************/
    41.  
    42. #include <QtGui>
    43.  
    44. #include "freezetablewidget.h"
    45. #include <CustomHeader.h>
    46.  
    47. FreezeTableWidget::FreezeTableWidget(QAbstractItemModel * model,CustomHeader *m_headerN)
    48. {
    49. setModel(model);
    50. // m_header=m_headerN;
    51. frozenTableView = new QTableView(this);
    52. m_header = new CustomHeader(Qt::Horizontal);
    53. m_header1= m_headerN;
    54. frozenTableView->setHorizontalHeader(m_header);
    55. init();
    56.  
    57. //connect the headers and scrollbars of both tableviews together
    58.  
    59.  
    60. connect( m_header1,SIGNAL(sectionResized(int,int,int)), this,
    61. SLOT(updateSectionWidth(int,int,int)));
    62. connect(verticalHeader(),SIGNAL(sectionResized(int,int,int)), this,
    63. SLOT(updateSectionHeight(int,int,int)));
    64.  
    65. connect(frozenTableView->verticalScrollBar(), SIGNAL(valueChanged(int)),
    66. verticalScrollBar(), SLOT(setValue(int)));
    67. connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
    68. frozenTableView->verticalScrollBar(), SLOT(setValue(int)));
    69.  
    70. }
    71.  
    72. FreezeTableWidget::~FreezeTableWidget()
    73. {
    74. delete frozenTableView;
    75. }
    76. void FreezeTableWidget::horizantalHeader_Hide()
    77. {
    78. frozenTableView->horizontalHeader()->hide();
    79. // QHeaderView *m_header1 = new CustomHeader(Qt::Horizontal);
    80. // frozenTableView->setHorizontalHeader(m_header1);
    81.  
    82. }
    83.  
    84. void FreezeTableWidget::init()
    85. {
    86. frozenTableView->setModel(model());
    87. frozenTableView->setFocusPolicy(Qt::NoFocus);
    88. frozenTableView->verticalHeader()->hide();
    89. // frozenTableView->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
    90. m_header->setResizeMode(QHeaderView::Fixed);
    91.  
    92. viewport()->stackUnder(frozenTableView);
    93.  
    94. frozenTableView->setStyleSheet("QTableView { border: none;"
    95. "background-color: #8EDE21;"
    96. "selection-background-color: #999}"); //for demo purposes
    97. frozenTableView->setSelectionModel(selectionModel());
    98. for(int col=1; col<model()->columnCount(); col++)
    99. frozenTableView->setColumnHidden(col, true);
    100.  
    101. frozenTableView->setColumnWidth(0, columnWidth(0) );
    102.  
    103. frozenTableView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    104. frozenTableView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    105. frozenTableView->show();
    106.  
    107. updateFrozenTableGeometry();
    108.  
    109. setHorizontalScrollMode(ScrollPerPixel);
    110. setVerticalScrollMode(ScrollPerPixel);
    111. frozenTableView->setVerticalScrollMode(ScrollPerPixel);
    112. }
    113.  
    114. void FreezeTableWidget::updateSectionWidth(int logicalIndex, int, int newSize)
    115. {
    116. qDebug()<<"Update Section Width";
    117. if(logicalIndex==0){
    118. frozenTableView->setColumnWidth(0,newSize);
    119. updateFrozenTableGeometry();
    120. }
    121. }
    122.  
    123. void FreezeTableWidget::updateSectionHeight(int logicalIndex, int, int newSize)
    124. {
    125. frozenTableView->setRowHeight(logicalIndex, newSize);
    126. }
    127.  
    128. void FreezeTableWidget::resizeEvent(QResizeEvent * event)
    129. {
    130. qDebug()<<"ResizeEvent";
    131.  
    132. QTableView::resizeEvent(event);
    133. updateFrozenTableGeometry();
    134. }
    135.  
    136. QModelIndex FreezeTableWidget::moveCursor(CursorAction cursorAction,
    137. Qt::KeyboardModifiers modifiers)
    138. {
    139. qDebug()<<"Move Cursor";
    140. QModelIndex current = QTableView::moveCursor(cursorAction, modifiers);
    141. m_header->showSection(0);
    142.  
    143. if(cursorAction == MoveLeft && current.column()>0
    144. && visualRect(current).topLeft().x() < frozenTableView->columnWidth(0) ){
    145.  
    146. const int newValue = m_header1->horizontalScrollBar()->value() + visualRect(current).topLeft().x()
    147. - frozenTableView->columnWidth(0);
    148. m_header1->horizontalScrollBar()->setValue(newValue);
    149. qDebug()<<newValue<<"newValue";
    150.  
    151. // m_header->viewport()->
    152. // horizontalScrollBar()
    153. }
    154. qDebug()<<"current"<<current;
    155. return current;
    156. }
    157.  
    158. void FreezeTableWidget::scrollTo (const QModelIndex & index, ScrollHint hint){
    159. if(index.column()>0)
    160. QTableView::scrollTo(index, hint);
    161. }
    162.  
    163. void FreezeTableWidget::updateFrozenTableGeometry()
    164. {
    165. // qDebug()<<"m_header->height()"<<m_header->height();
    166. frozenTableView->setGeometry( verticalHeader()->width()+frameWidth(),
    167. frameWidth(), columnWidth(0),
    168. viewport()->height()+m_header1->height());
    169. }
    170. //m_header->height()
    To copy to clipboard, switch view to plain text mode 


    where i am doing wrong .. I Need it today itself . Please help me anyone .
    Last edited by RameshNani; 30th January 2015 at 04:38.

  15. #15
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How To Apply Scroll Only for few columns of QTableview

    If you do not apply custom headers do the standard headers work as you expect they should?

    If so, then the problem is in your header code and not the frozen column code.

  16. #16
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Apply Scroll Only for few columns of QTableview

    Yeah , with this custom header i am facing this issue . when i use normal header view it's working fine , how could i modify my custom header , please help me , i need both functionalities .

  17. #17
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How To Apply Scroll Only for few columns of QTableview

    Here are possible problems.:
    • If the rect for the section being painted does not contain the cursor then you paint the section regardless of whether it is visible or not. Without delving into the Qt code I do not know if paintsection is called only for visible sections or not, but this is worth checking.
    • If the rect contains the pointer then you paint the default visual for the cell and then paint over it. You then paint the next/previous buttons based on whether the next logical index is visible or not. This is not the same as checking whether there is another visible column to the left or right.

    Perhaps if you posted a screen shot of the problem it would be more apparent where the problem lay.

  18. #18
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Apply Scroll Only for few columns of QTableview

    Hi ,

    When i hide custom header am able to see frozen columns headers , but when i remove hide of custom header , am unable to see frozen headers , the frozen headers also overridden from custom header . even when i set some header sections hide in custom headers also the headers are painted , i don't know why they are painted , it might happen due to am not checking hidden sections in custom header paint section . I posted my code as it is . Could you show me any solution for this issue .

    I Attached Screen shots of my issue . Before horizontal scroll and after scroll , the 1st two columns are frozen but the headers are moving unless of freez with columns by the reason of custom header .
    Attached Images Attached Images
    Last edited by RameshNani; 1st February 2015 at 04:05.

  19. #19
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How To Apply Scroll Only for few columns of QTableview

    It looks like your base table custom header is stacked on top of the frozen column overlay's headers.

    Move the call to set the horizontal header of the base table view into the FreezeTableWidget init() routine (it is in you MainWindow at the moment).
    Move the call to set the horizontal header of the frozen column view into the FreezeTableWidget init() routine.
    Apply both custom headers before you call "viewport()->stackUnder(frozenTableView);" to make sure the base table is underneat the frozen column overlay.

    Help?

  20. #20
    Join Date
    Feb 2014
    Posts
    43
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Apply Scroll Only for few columns of QTableview

    Sorry , I didn't understand could you please explain with my code snippet .

Similar Threads

  1. Replies: 0
    Last Post: 13th January 2013, 00:20
  2. Distribute columns in QTableView
    By qlands in forum Qt Programming
    Replies: 1
    Last Post: 17th August 2011, 14:33
  3. Validator for QTableView columns
    By sasi in forum Qt Programming
    Replies: 0
    Last Post: 6th October 2009, 08:10
  4. Don't resize columns - QTableView
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2009, 16:59
  5. autoexpanding QTableView columns
    By ucntcme in forum Qt Programming
    Replies: 6
    Last Post: 11th March 2008, 09:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.