Page 2 of 2 FirstFirst 12
Results 21 to 22 of 22

Thread: how i can chagne Qtableview horizontal header text as well as remove Indexes vHeader

  1. #21
    Join Date
    Jul 2013
    Posts
    54
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how i can chagne Qtableview horizontal header text as well as remove Indexes vHea

    Quote Originally Posted by Santosh Reddy View Post
    Here you go, keyboard only operation

    Qt Code:
    1. // Handles Horizontal header
    2. class HeaderModel : public QSortFilterProxyModel
    3. {
    4. Q_OBJECT
    5.  
    6. public:
    7. explicit HeaderModel(QObject * parent = 0)
    8. { }
    9.  
    10. QVariant headerData(int section, Qt::Orientation orientation, int role) const
    11. {
    12. if(orientation == Qt::Horizontal)
    13. {
    14. if(role == Qt::DisplayRole)
    15. switch(section)
    16. {
    17. case 0: return "Id"; break;
    18. case 1: return "Designation"; break;
    19. case 2: return "Famille"; break;
    20. case 3: return "Qte Maximum"; break;
    21. case 4: return "Qte Minimum"; break;
    22. case 5: return "Prix"; break;
    23. case 6: return "Prix vente"; break;
    24. default:
    25. return QString("Column %1").arg(section + 1);
    26. break;
    27. }
    28. }
    29.  
    30. return QVariant();
    31. }
    32. };
    33.  
    34. // Handles Vertical header
    35. class Header : public QHeaderView
    36. {
    37. Q_OBJECT
    38. public:
    39. explicit Header(QWidget * parent)
    40. : QHeaderView(Qt::Vertical, parent)
    41. , mSelectedIndex(-1)
    42. {
    43. setMinimumWidth(QImage("imgs/arrow.png").width());
    44. }
    45.  
    46. public slots:
    47. void changeCurrent(const QModelIndex & current, const QModelIndex & previous)
    48. {
    49. int section = current.row();
    50.  
    51. if(mSelectedIndex != section)
    52. {
    53. mSelectedIndex = section;
    54. viewport()->update();
    55. }
    56. }
    57.  
    58. protected:
    59. void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
    60. {
    61. painter->save();
    62. if(mSelectedIndex > -1)
    63. {
    64. if(mSelectedIndex == logicalIndex)
    65. if(!isSectionHidden(logicalIndex))
    66. painter->drawImage(rect, QImage("imgs/arrow.png"));
    67. }
    68. painter->restore();
    69. }
    70.  
    71. private:
    72. int mSelectedIndex;
    73. };
    74.  
    75. //Usage
    76.  
    77. HeaderModel headerModel;
    78. headerModel.setSourceModel(&model);
    79.  
    80. QTableView tableView;
    81. Header * header = new Header(&tableView);
    82. tableView.setModel(&headerModel);
    83. tableView.connect(tableView.selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), header, SLOT(changeCurrent(QModelIndex,QModelIndex)));
    84. tableView.setVerticalHeader(header);
    85. tableView.setSelectionMode(QAbstractItemView::SingleSelection);
    86. tableView.setSelectionBehavior(QAbstractItemView::SelectRows);
    87. tableView.show();
    To copy to clipboard, switch view to plain text mode 
    Yes this is working perfectly, but i get hard to resize the icon ,

    i tried setFixedWidth() and setFixedHigh() but the icon becomes broken
    i want like QtableWidget when we set an icon it resizes automatically

    thanks Santosh Reddy

  2. #22
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how i can chagne Qtableview horizontal header text as well as remove Indexes vHea

    Then set the minimum size of the icon, that will allow it to increase it's size when required.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. QTableView Hidden Sections and Indexes
    By mechsin in forum Newbie
    Replies: 1
    Last Post: 15th July 2012, 18:49
  2. Replies: 1
    Last Post: 2nd May 2010, 00:03
  3. QTableView Horizontal Header's Width
    By araglin in forum Newbie
    Replies: 3
    Last Post: 21st December 2008, 09:54
  4. How to set QTableView width to width of horizontal header?
    By martinb0820 in forum Qt Programming
    Replies: 0
    Last Post: 2nd December 2008, 21:51
  5. How to customize horizontal header (diagonal header view)
    By vairamuthu.g in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2008, 16:59

Tags for this Thread

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.