View Full Version : change Qtablewidget vertical header displayrole
advseo32
27th July 2013, 13:20
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
advseo32
27th July 2013, 20:46
Plz give me somme hints
ChrisW67
28th July 2013, 00:57
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.
advseo32
28th July 2013, 20:46
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
QModelIndex index ;
index = tableau->model()->index(0,0) ;
tableau->verticalHeader()->model()->setData(index,"*",Qt::DisplayRole);
but the cell was changed not the cell in vertical header
advseo32
30th July 2013, 01:13
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
#include "dialog.h"
Dialog::Dialog(QWidget *parent)
: QWidget(parent)
{
layoutPrincipale = new QVBoxLayout(this);
QPushButton *button = new QPushButton("Clear",this);
tableau = new MonTableauWidget(this);
tableau->setRowCount(1);
tableau->setColumnCount(4) ;
tableau->setCurrentIndex(tableau->model()->index(0,0,QModelIndex()));
//tableau->setCurrentIndex();
// QKeyEvent event(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier);
QStringList list ;
list << "Désignation" << "Qte" << "Prix/U" << "Total";
tableau->setHorizontalHeaderLabels(list);
tableau->setCurrentCell(0,0);
layoutPrincipale->addWidget(tableau);
layoutPrincipale->addWidget(button);
setLayout(layoutPrincipale);
//connect(tableau,SIGNAL(cellChanged(int,int)),this, SLOT(addrow(int,int))) ;
connect(button,SIGNAL(clicked()),tableau,SLOT(clea r()));
connect(tableau,SIGNAL(itemSelectionChanged()),thi s,SLOT(newfunction()));
}
Dialog::~Dialog()
{
}
void Dialog::addrow(int row, int col)
{
if(col == 0)
tableau->insertRow(tableau->rowCount());
}
void Dialog::newRecod(QKeyEvent *record)
{
}
void Dialog::newfunction()
{
QTableWidgetItem * item = new QTableWidgetItem() ;
item->setIcon( *(new QIcon("imgs/editIcon.png")));
tableau->setVerticalHeaderItem(0,item);
for (int rowToDelete=0; rowToDelete < tableau->rowCount(); ++rowToDelete)
{
if(rowToDelete != 0)
tableau->takeVerticalHeaderItem(rowToDelete);
}
}
ChrisW67
30th July 2013, 05:29
i have use this
QModelIndex index ;
index = tableau->model()->index(0,0) ;
tableau->verticalHeader()->model()->setData(index,"*",Qt::DisplayRole);
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.
QHeaderView *verticalHeader = tableau->verticalHeader(); // From QTableView obtain verticalHeader()
QAbstractItemModel *headerModel = verticalHeader->model(); // From the vertical header obtain the model()
QModelIndex index = headerModel->index(0, 0); // index of first row header
headerModel->setData(index, "*"); // From the model you can call setData() to change the text
You could also try this:
QAbstractItemModel *tableModel = tableau->model();
tableModel->setHeaderData(0, Qt::Vertical, "*");
advseo32
30th July 2013, 08:37
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:)
ChrisW67
30th July 2013, 11:59
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.
advseo32
30th July 2013, 13:35
after reading Qtablewidget class i have gotted an idea and it works perfectly
her is the code
QTableWidgetItem * item = new QTableWidgetItem() ;
item->setIcon( *(new QIcon("imgs/editIcon.png")));
tableau->setVerticalHeaderItem(row,item);
the only probleme is how i can catch when the user start editing cell or typing a text
regards
advseo32
12th August 2013, 00:55
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 ???
advseo32
12th August 2013, 14:21
any body can help me
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.