Results 1 to 12 of 12

Thread: Split pane view with different headers.

  1. #1
    Join Date
    Jun 2008
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default 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:

    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.

  2. #2
    Join Date
    Jun 2008
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Split pane view with different headers.

    To clarify, I have the following structures.

    Qt Code:
    1. struct Order
    2. {
    3. int quantity;
    4. double price;
    5. QString currency;
    6. };
    7.  
    8. struct Account
    9. {
    10. QString accountId;
    11. QString holderName;
    12. QString holderAddress;
    13. OrderList orders;
    14. };
    To copy to clipboard, switch view to plain text mode 


    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.

  3. #3
    Join Date
    Feb 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question 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.
    Last edited by chocolate; 3rd February 2009 at 23:06.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Split pane view with different headers.

    Use a proxy model where you will reimplement headerData() to return new column descriptions.

  5. #5
    Join Date
    Feb 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question 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.


    I was able to see this error:

    signal SEGV (no mapping at the fault address) in QSortFilterProxyModel Private:roxy_to_source at 0xfe8a7180
    Last edited by chocolate; 5th February 2009 at 23:10.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Split pane view with different headers.

    Can we see the code?

  7. #7
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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?

  8. #8
    Join Date
    Feb 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.
    Last edited by chocolate; 9th February 2009 at 19:53.

  9. #9
    Join Date
    Feb 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Unhappy 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.

  10. #10
    Join Date
    Feb 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation Re: Split pane view with different headers.

    Has anyone seen this or have any ideas? I really need to get this working.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Split pane view with different headers.

    Did you remember to emit appropriate signals from the proxy when "things happen" in the base model?

  12. #12
    Join Date
    Feb 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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).

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.