Results 1 to 11 of 11

Thread: change Qtablewidget vertical header displayrole

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

    Question change Qtablewidget vertical header displayrole

    Hi every body,

    i want to change the behavior of vertical header in Qtableview

    this is what i mean:

    when user start fill table cells, i want this sign(*) present in vertical header instead of numbers

    when user moves beteween rows , i want also this sign(>) present in vertical header instead of numbers

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

    Default Re: change Qtablewidget vertical header displayrole

    Plz give me somme hints

  3. #3
    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: change Qtablewidget vertical header displayrole

    From QTableView obtain verticalHeader()
    From the vertical header obtain the model()
    From the model you can call setData() to change the text, colour, font, pixmap etc. of any vertical header entry.

    You might need to use a QStyledItemDelegate on the table to signal when an editor is opened/close so that you can change the vertical header on that row.

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

    Default Re: change Qtablewidget vertical header displayrole

    Quote Originally Posted by ChrisW67 View Post
    From QTableView obtain verticalHeader()
    From the vertical header obtain the model()
    From the model you can call setData() to change the text, colour, font, pixmap etc. of any vertical header entry.

    You might need to use a QStyledItemDelegate on the table to signal when an editor is opened/close so that you can change the vertical header on that row.
    i have use this

    Qt Code:
    1. QModelIndex index ;
    2. index = tableau->model()->index(0,0) ;
    3. tableau->verticalHeader()->model()->setData(index,"*",Qt::DisplayRole);
    To copy to clipboard, switch view to plain text mode 

    but the cell was changed not the cell in vertical header

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

    Default Re: change Qtablewidget vertical header displayrole

    i have uses another way because really i don't know, how i can catch "the opening and closing of editor in Qstyleditemdelegate, like what you said

    her is my code
    Qt Code:
    1. #include "dialog.h"
    2.  
    3. Dialog::Dialog(QWidget *parent)
    4. : QWidget(parent)
    5. {
    6. layoutPrincipale = new QVBoxLayout(this);
    7. QPushButton *button = new QPushButton("Clear",this);
    8. tableau = new MonTableauWidget(this);
    9. tableau->setRowCount(1);
    10. tableau->setColumnCount(4) ;
    11. tableau->setCurrentIndex(tableau->model()->index(0,0,QModelIndex()));
    12.  
    13. //tableau->setCurrentIndex();
    14. // QKeyEvent event(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier);
    15.  
    16.  
    17. QStringList list ;
    18. list << "Désignation" << "Qte" << "Prix/U" << "Total";
    19. tableau->setHorizontalHeaderLabels(list);
    20. tableau->setCurrentCell(0,0);
    21. layoutPrincipale->addWidget(tableau);
    22. layoutPrincipale->addWidget(button);
    23. setLayout(layoutPrincipale);
    24. //connect(tableau,SIGNAL(cellChanged(int,int)),this,SLOT(addrow(int,int))) ;
    25. connect(button,SIGNAL(clicked()),tableau,SLOT(clear()));
    26. connect(tableau,SIGNAL(itemSelectionChanged()),this,SLOT(newfunction()));
    27.  
    28. }
    29.  
    30. Dialog::~Dialog()
    31. {
    32.  
    33. }
    34.  
    35. void Dialog::addrow(int row, int col)
    36. {
    37. if(col == 0)
    38. tableau->insertRow(tableau->rowCount());
    39. }
    40.  
    41. void Dialog::newRecod(QKeyEvent *record)
    42. {
    43.  
    44. }
    45.  
    46. void Dialog::newfunction()
    47. {
    48. item->setIcon( *(new QIcon("imgs/editIcon.png")));
    49. tableau->setVerticalHeaderItem(0,item);
    50. for (int rowToDelete=0; rowToDelete < tableau->rowCount(); ++rowToDelete)
    51. {
    52. if(rowToDelete != 0)
    53. tableau->takeVerticalHeaderItem(rowToDelete);
    54. }
    55.  
    56. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    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: change Qtablewidget vertical header displayrole

    Quote Originally Posted by advseo32 View Post
    i have use this

    Qt Code:
    1. QModelIndex index ;
    2. index = tableau->model()->index(0,0) ;
    3. tableau->verticalHeader()->model()->setData(index,"*",Qt::DisplayRole);
    To copy to clipboard, switch view to plain text mode 

    but the cell was changed not the cell in vertical header
    No, because you are attempting to manipulate the model underlying the header with an index from the model underlying the table.
    Qt Code:
    1. QHeaderView *verticalHeader = tableau->verticalHeader(); // From QTableView obtain verticalHeader()
    2. QAbstractItemModel *headerModel = verticalHeader->model(); // From the vertical header obtain the model()
    3. QModelIndex index = headerModel->index(0, 0); // index of first row header
    4. headerModel->setData(index, "*"); // From the model you can call setData() to change the text
    To copy to clipboard, switch view to plain text mode 

    You could also try this:
    Qt Code:
    1. QAbstractItemModel *tableModel = tableau->model();
    2. tableModel->setHeaderData(0, Qt::Vertical, "*");
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: change Qtablewidget vertical header displayrole

    It seems that you haven't understand me "if so, sorry my english i too bad"

    I'm using QtableWidget not Qtableview

    i want this sign(*) appears in verticalheader when the start editing or typing in one of cell

    also i want another icon shown when the user change selection of row (means when the user go from row1 to row2 or to row0)

    i hope this is clear for you

    thank's

  8. #8
    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: change Qtablewidget vertical header displayrole

    QTableWidget is a QTableView
    I am telling you how to change the text in the header. You still need to work out when to change it.

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

    Default Re: change Qtablewidget vertical header displayrole

    after reading Qtablewidget class i have gotted an idea and it works perfectly

    her is the code

    Qt Code:
    1. item->setIcon( *(new QIcon("imgs/editIcon.png")));
    2. tableau->setVerticalHeaderItem(row,item);
    To copy to clipboard, switch view to plain text mode 

    the only probleme is how i can catch when the user start editing cell or typing a text

    regards

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

    Default Re: change Qtablewidget vertical header displayrole

    You might need to use a QStyledItemDelegate on the table to signal when an editor is opened/close so that you can change the vertical header on that row.
    how i detect when the editor is opened ???

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

    Default Re: change Qtablewidget vertical header displayrole

    any body can help me

Similar Threads

  1. Change tableView vertical header
    By tinysoft in forum Newbie
    Replies: 1
    Last Post: 17th September 2011, 08:35
  2. Replies: 3
    Last Post: 20th January 2011, 13:24
  3. Vertical Header For QTreeView
    By wirasto in forum Qt-based Software
    Replies: 1
    Last Post: 12th October 2010, 05:53
  4. Replies: 2
    Last Post: 17th July 2010, 21:07
  5. Change QTableWidget header name or text
    By ricardo in forum Qt Programming
    Replies: 3
    Last Post: 14th May 2009, 11:37

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.