Hi All,

I am attempting to create a model/view application in Qt 4.7.1. I am a very new Qt developer.

Summary of what I am attempting to do:

I have a treeview that is organized as a rectangular table of rows and columns. One column of items contains a button. By default this button is to be transparent and disabled. A given button is to become visible and enabled when the mouse is hovering over its row.

The approach I am pursuing is to

1. find the model index for the cell that the mouse is hovering over, and
2. obtain a pointer to the widget associated with the widget, and
3. using this pointer manipulate the visibility of the button within said widget.

I cannot get a valid pointer to the widget.

my current code looks like this:

void HistoryTreeView::mouseMoveEvent(QMouseEvent *event)
{
QAbstractItemModel *m(model());

// Only do something when a model is set.
if (m)
{
QModelIndex index = indexAt(event->pos());
if (index.isValid())
{
// if the mouse has moved to another row
if (index.row() != m_currentRow)
{
m_currentRow = index.row();

QMessageBox::information( this, "HistoryTreeView", QString("index(%1)").arg(index.row()));

QWidget * item = indexWidget(index);
Q_ASSERT(item != NULL );
}
}
else // model is invalid
{
m_currentRow = -1;
}
}
}

The symptoms:

I expected the call to indexWidget() to return a valid pointer to the widget the mouse is over. Instead it unexpectedly returns a NULL pointer.

Commentary:

The variable named 'index' is acting as I expected because the QMessageBox shows the correct row value. Consequently I do not think there is anything wrong with the value I am providing to indexWidget().

This is just debug code. It is missing things like code that selects the column that holds the buttons.