Tuesday 15 April 2014

c++ - Change QHeaderView data -



c++ - Change QHeaderView data -

i seek modify text of qheaderview (horizontal) in qtablewidget.

first question: possible set editable qtablewidgetitem ?

second question: if it's not possible, how can that, tried repaint this:

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]); }

but header index painted behind text.

another solution tried is:

void editableheaderview::mysectiondoubleclicked( int section ) { if (section != -1) // not on section m_svalues[section] = qinputdialog::gettext(this, tr("enter value"), tr("enter value"), qlineedit::normal, ""); qabstractitemmodel* model = this->model(); model->setheaderdata(section, this->orientation(), m_svalues[section]); this->setmodel(model); }

but doesn't works...

i hope have solution.

thank !

it can done without subclassing, don't need paint section set text, setheaderdata. illustration next code works without errors.

//somewhere in constructor illustration connect(ui->tablewidget->horizontalheader(),&qheaderview::sectiondoubleclicked,[=]( int logicalindex) {//with lambda qdebug() << "works"; qstring txt = qinputdialog::gettext(this, tr("enter value"), tr("enter value"), qlineedit::normal, ""); ui->tablewidget->model()->setheaderdata(logicalindex,qt::horizontal,txt); });

before:

after:

i used here c++11 (config += c++11 .pro file) , new syntax of signals , slots, of course of study can utilize old syntax if want.

c++ qt qtablewidget qheaderview

No comments:

Post a Comment