I am back with another doubt
I want to add a new row (this should be the 1st row in th table) in my table view with a push button or a label. The label or push button will be named "ALL" and i need to trap the click event on the label/button.
Basically the "ALL" button/label will be used for checking/unchecking all checkboxes at once. So, if user wants to click all checkboxes in the 4th column, he'll click on the "ALL" button in the 4th column to check all checkboxes.
Now, is it possible to add push button or a label in the table model? i used the following code to add one additional row for the push button/label in the table:
So, i have added 1 to the number of rows to add one extra row. But the problem is that the new row is added to the bottom of the table i.e. after all model data. I want to add it to the top of the table.int TableModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return m_tableData.size() + 1;
}
Secondly, i think i can't return a widget pointer from data() function of the model, so i tried creating a label using the following code in data() function:
This shows a label named "ALL" in the 4th column and last row of the table. Now, how can i trap the click of this and select all checkboxes?if (role == Qt:isplayRole && index.row() >= m_tableData.size() && index.column() == 3) {
return QVariant("ALL");
}
Edit: It seems i can trap the click of the label by trapping click() signal of QAbstractItemView() so it shouldn't be a problem.
But how can i make the label/push button appear on the 1st row instead of the last row? and for selecting all checkboxes, i can use setData() function and pass the value (check or uncheck) in the 2nd argument. Is it correct?
Last edited by montylee; 23rd December 2008 at 22:37.
My GNU/Linux Blog:
http://funwithlinux.blogspot.com
bump.
Anybody knows a solution to my problem?
My GNU/Linux Blog:
http://funwithlinux.blogspot.com
Adding a button to the model doesn't make sense, this would break the logic-presentation separation. What you want is to modify the view. The usual way to do what you want would be simply to make it so that if you click on the header in the appropriate column (the one with checkboxes) all checks will go on or off. But if you want to do it "your way", you can use QAbstractItemView::setIndexWidget() for instance or you can use QAbstractScrollArea::setViewportMargins() to move the viewport down and place the button in the extra space between the header and the viewport.
Of course you might also make the header checkable as in the image below.
thanks! Actually i have placed the button to select all checkbox outside the QTableView for now. Based on the requirement i might be required to place it inside QTableView but still instead of the button i'll simply use a clickable label or icon for the same.
My GNU/Linux Blog:
http://funwithlinux.blogspot.com
Bookmarks