我尝试在我的 QTableWidget 中修改我的 QHeaderView (Horizontal) 的文本。
第一个问题:是否可以像 QTableWidgetItem 一样将其设置为可编辑?
第二个问题:如果不可能,我该怎么做,我试着像这样重新粉刷它:
void EditableHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
{
painter->save();
QHeaderView::paintSection(painter, rect, logicalIndex);
painter->restore();
painter->setPen(Qt::SolidLine);
painter->drawText(rect, Qt::AlignCenter, m_sValues[logicalIndex]);
}
但是标题索引画在我的文字后面。
我尝试的另一个解决方案是:
void EditableHeaderView::mySectionDoubleClicked( int section )
{
if (section != -1) // Not on a section
m_sValues[section] = QInputDialog::getText(this, tr("Enter a value"), tr("Enter a value"), QLineEdit::Normal, "");
QAbstractItemModel* model = this->model();
model->setHeaderData(section, this->orientation(), m_sValues[section]);
this->setModel(model);
}
但这不起作用...
我希望有人有解决方案。
谢谢 !