PDA

View Full Version : adding in values to table



therealjag
8th February 2006, 23:54
hello there, i have created a table using QTableWidget class which is inserted inside a tabWidget. i want to add a character "*" diagonally across all the cells which relate to the same number i.e. stick "*" which relates to (0,0)(1,1) and (2,2) etc because i dont want the user to enter any data in they fields. i tried using addItem( ) with a while loop and a for loop to add in the character but this gave me errors after running the program. is there any quick way to do this without having to use addItem individually for each cell?? heres my code that i tried to use for the table:

DemandsTab::DemandsTab(const QFileInfo &fileInfo, QWidget *parent)
: QWidget(parent)
{

int rows = 0, columns = 0;

QLabel *testme = new QLabel(tr("Suck it the 4th time"));

QTableWidget *demands = new QTableWidget(this);

demands->setRowCount(10);
demands->setColumnCount(10);

int row = demands->rowCount();
int column = demands->columnCount();

QTableWidgetItem *nodesHeaderItem = new QTableWidgetItem(tr("Cubes"));
nodesHeaderItem->setTextAlignment(Qt::AlignVCenter);



QTableWidgetItem *asterix = new QTableWidgetItem(tr("*").arg((row+1)+(column+1)));


---------------heres where the problem lies-------

for(int i=0;i<10;i++)
{
demands->setItem(rows, columns, asterix);
rows++;
columns++;
)


-----------------------------------------------------------
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(testme);
mainLayout->addWidget(demands);
mainLayout->addStretch(0);
setLayout(mainLayout);
}


any help would be much appreciated thanks, Jag

wysota
9th February 2006, 00:02
Try:


for(int i=0;i<10;i++){
demands->setitem(i,i, new QTableWidgetItem("*"));
}

therealjag
9th February 2006, 16:05
cool man it worked, your solution was much simpler in the end i guess it comes with experience, thanks.

actaully there is 1 more thing. is there a way to write protect the cells with the asterixes in them so that the user cant write any values into them?