Split pane view with different headers.
Hello,
I am facing the same problem discussed in a previous thread but the thread is quote old so I figured I would start a new discussion. Basically I want to use two table views in a split pane view, with the bottom table showing children of the item selected in the upper one. I would prefer to use the same model in both tables, however the tables need different headers. I am trying to implement a hierarchical model as suggested by wysota in the other thread:
Quote:
So you could say that the bottom table show "children" of the item selected in the upper table?
If so, then why not make a proper hierarchical model with parents and children. Then populating the bottom table would be as simple as setting the root index to the index of the item selected in the upper table.
Regardless of your decision, the headers could be changed by using a proxy model over the sqlquery (or your custom) model.
This makes sense, however I don't know how to go about mapping to and from the source index in the proxy model, and how the source index relates to the root index that would be set in the bottom table on a new item selection in the upper table.
Any help would be appreciated.
Re: Split pane view with different headers.
To clarify, I have the following structures.
Code:
struct Order
{
int quantity;
double price;
};
struct Account
{
OrderList orders;
};
I want to display the account details in a split pane view where the upper table would show account details such as id, name, address, etc. and the bottom table would show the list of orders. The tables would have different headers, and I would like to set them up from the same item model.
Re: Split pane view with different headers.
Does anyone have an answer to this? Specifically how to provide the different headers for the different views of a single model.
Thanks.
Re: Split pane view with different headers.
Use a proxy model where you will reimplement headerData() to return new column descriptions.
Re: Split pane view with different headers.
Thanks for the response.
I tried to implement a QSortFilterProxyModel on the tree view/model and it seg faults. I just implemented the lessThan and the filterAcceptsRow returning true in each to allow everything to display at first.
I also implemented a proxy model based on QAbstractProxyModel and it does not display anything in my view, so I'm not sure that I implemented it correctly, but it doesn't seg fault.
Just using the model itself with the view works fine.
Any ideas about what I could look at or does anyone have any good examples of a tree model/proxy/view...more than the simple ones that are available?
Any help is appreciated. :confused:
I was able to see this error:
signal SEGV (no mapping at the fault address) in QSortFilterProxyModel Private::proxy_to_source at 0xfe8a7180
Re: Split pane view with different headers.
Re: Split pane view with different headers.
Wild guesses:
i) are you sure there is a (valid!) model inside your proxy model?
ii) maybe you have some signals attached to the QTreeView that now no longer contain QModelIndexes of "your" model but of the proxy?
Re: Split pane view with different headers.
I figured out my problem. In my QSortFilterProxyModel, I had to reimplement all the public methods from my model.
One other question, do I need to reimplement the mapToSource and mapFromSource in my QSortFilterProxyModel or will the base methods work?
I ask because I have not reimplemented them and when I set a certain location to expand in the tree view, it is expanding the wrong location in the view, so it's like it's getting the wrong indices for the items.
Re: Split pane view with different headers.
Okay, any help from anyone will be much appreciated. I've worked through any of the above problems that I had.
I have a model, a tree proxy model and a table proxy model and two views a tree view and a table view. The Proxy's are based on QSortFilterProxy. The treeview gets the data and displays it (filtered to be only folders). The table view is supposed to only display the data matching it's set parent, for example a users home directory. The treeview/proxy model works fine.
The problem is that the table view/proxy does not recieve data from the model. If I connect a signal/SLOT on rowsInserted, then I can see that the filter sees the top level data, but does not display anything. In addition, the table proxy model's data method is never called.
Here are some snippets.
class MyDataModel : QAbstractItemModel
class MyTreeProxyModel : QSortFilterProxyModel
class MyTableProxyModel : QSortFilterProxyModel
QTreeView *myTreeView;
QTableView *myTableView;
In Mainwindow::Mainwindow()
MyDataModel *dataModel = new MyDataModel();
// Sets the root directory to display
dataModel->setRoot("/");
MyTreeProxyModel *treeProxy = new MyTreeProxyModel();
MyTableProxyModel *tableProxy = new MyTableProxyModel();
treeProxy->setSourceModel(dataModel);
tableProxy->setSourceModel(dataModel);
// Sets the directory on which to filter..
tableProxy->setParent("/home/user1");
myTreeView = new QTreeView();
myTreeView->setModel(treeProxy);
myTableView = new QTableView();
myTableView->setModel(tableProxy);
QSplitter* splitter = new QSplitter(this);
splitter->addWidget(myTreeView);
splitter->addWidget(myTableView);
setCentralWidget(splitter);
//This starts the process, i.e. the tree view recieves and displays data
setRootPath("/home/user1");
---------------------------------------
What I need to do is display a list of folders on one side in a tree and in the other side in tabular form, information about the children of a selected folder. You can think of windows explorer in how it's supposed to behave.
Example data:
FOLDERS----------------------------------------- NAME INFO1 INFO2 INFO3
/folder1------------------------------------------- file1 info1 info2 info3
/folder2------------------------------------------- file2 info1 info2 info3
+/home/user1
/file1
/file2
/folder3
.
.
.
I appreciate any help in advance.
Re: Split pane view with different headers.
Has anyone seen this or have any ideas? I really need to get this working.
Re: Split pane view with different headers.
Did you remember to emit appropriate signals from the proxy when "things happen" in the base model?
Re: Split pane view with different headers.
Yes, I do emit the signal and see that it is emited and received.
I can also see the data going through the filter, but the tableProxy's data method is never called. The treeproxy's data method is called (although it's just a pass through to the underlying model).