Domanda

I know there are similar questions, but none of them have a solution. The Qt documentation specifies this for QAbstractScrollArea::setViewportMargins():

"Sets the margins around the scrolling area to left, top, right and bottom. This is useful for applications such as spreadsheets with "locked" rows and columns. The marginal space is is left blank; put widgets in the unused area. Note that this function is frequently called by QTreeView and QTableView, so margins must be implemented by QAbstractScrollArea subclasses. Also, if the subclasses are to be used in item views, they should not call this function. By default all margins are zero."

I was able to create the space for the frozen row by calling setViewportMargins, but I can't figure out how to place a control in that space. Does anyone know how to do this?

È stato utile?

Soluzione

You should look into the code editor example.

Basically you just place a widget over the viewport margin. You also have to resize your widget when you QTableView object is resized. This of course is done in the resize event of your QTableView object.

This is how it's done in the example:

void CodeEditor::resizeEvent(QResizeEvent *e)
{
    QPlainTextEdit::resizeEvent(e);

    QRect cr = contentsRect();
    lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top