I was writing a simple table code. I want to align the text in center. I tried using
cell(row, column)->setTextAlignment(Qt::AlignRight);
but it does not work. The text stays aligned to left in the cell.
Also, another question. I know that QTableWidget has show grid slot. I implemented the slot using a toggled(bool) signal with a menu action. However, I dont notice any change.
Here is the part of code..
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
|
void Spreadsheet:: alignRight() {
QTableWidgetSelectionRange range = selectedRange();
for (int i=0; i<range.rowCount(); ++i) {
for (int j=0; j<range.columnCount(); ++j) {
Cell *c = cell(range.topRow() + i, range.leftColumn() +j);
c->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
c->setDirty();
}
}
viewport()->update();
}
|
for showgrid..
|
Source code
|
1
2
3
4
5
|
showGridAction = new QAction(tr("&Show Grid"), this);
showGridAction->setCheckable(true);
showGridAction->setChecked(spreadsheet->showGrid());
showGridAction->setStatusTip(tr("Show or hide spreadsheet's grid"));
connect(showGridAction, SIGNAL(toggled(bool)), this, SLOT(setShowGrid(bool)));
|