Results 1 to 7 of 7

Thread: Linking of 2 QTableViews

  1. #1
    Join Date
    Jul 2011
    Location
    Belgium
    Posts
    24
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Question Linking of 2 QTableViews

    Hi,

    At the moment, I have 2 tables. 1 table (name it fileTableView) containts a couple of columns and rows containing data. The second table (call it selectionTableView) has the selected data of the first table (fileTableView).

    Now the two tables are aligned horizontal. First you have the fileTableView and beneath that, you have the selectionTableView. Both table views show the exact same columns. For example a column "File Name". When you now change the geometries of the column File Name, for example the width of the column (by dragging the mouse), the same column File Name in the selectionTableView must also change it's geometries. So that I get exactly two of the same table views but with one table containing the selected data from the first table.

    Anyone has an idea?

    Greetings,
    Robin

  2. #2
    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: Linking of 2 QTableViews

    Connect to the QHeaderView::sectionResized() signal of one table and adjust the size of the other table's headers.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Taxi (4th October 2011)

  4. #3
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Linking of 2 QTableViews

    In the first view,you could have :

    Qt Code:
    1. connect(ui.filesView->selectionModel(),
    2. SIGNAL(currentRowChanged(const QModelIndex&,
    3. const QModelIndex&)),
    4. this, SLOT(updateFileView()));
    To copy to clipboard, switch view to plain text mode 

    The updated view could have a view with data from the selected file from the first view.

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Linking of 2 QTableViews

    Seems odd to go to all this effort to duplicate the supplied selection highlighting.

  6. #5
    Join Date
    Jul 2011
    Location
    Belgium
    Posts
    24
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Linking of 2 QTableViews

    Quote Originally Posted by wysota View Post
    Connect to the QHeaderView::sectionResized() signal of one table and adjust the size of the other table's headers.
    Thanks! I've tried your solution but the wierd thing is that the signal sectionResized doenst get emitted... I've tried a couple of things but everytime when i want to use a signal, it just doens't get emitted when I resize my column. Any idea?

    The way I try to connect:

    Qt Code:
    1. QObject::connect(m_fileTableView->horizontalHeader(),SIGNAL(sectionResized(int,int,int)),m_selectionTableView,SLOT(onSectionResized(int,int,int)));
    To copy to clipboard, switch view to plain text mode 

    The onSecionResized is defined as a public slot, as it should be. In this slot, I do the following:

    Qt Code:
    1. QHeaderView* selectionHeader = m_selectionTableView->horizontalHeader();
    2. if(selectionHeader)
    3. return selectionHeader->resizeSection(index, newSize);
    4. else
    5. return ;
    To copy to clipboard, switch view to plain text mode 

    But ok, in debug mode, while using breakpoints, the slot doens't get called. So this means the signals just doens't get emitted.

    Quote Originally Posted by ChrisW67 View Post
    Seems odd to go to all this effort to duplicate the supplied selection highlighting.
    Well it does look wierd. What I have is at the left om my screen a file tree view. With this view, I go to a certain folder containing hunderds of measurement files written in a .txt file. All these measurement files are read and certain parameters are loaded into my first table view. The second table view let's me see the selected items from the first table view, but only those selected items. Now, these selected items from the first table view, are selected by a function that looks at the parameters and makes an automatic selection, it's actually a filter to all the measurement files.
    With only the selected measurement in the second table view, I create a graph.
    Last edited by Taxi; 4th October 2011 at 10:30. Reason: Adding code

  7. #6
    Join Date
    Apr 2011
    Posts
    67
    Thanks
    22
    Thanked 5 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Linking of 2 QTableViews

    Quote Originally Posted by Taxi View Post
    Thanks! I've tried your solution but the wierd thing is that the signal sectionResized doenst get emitted... I've tried a couple of things but everytime when i want to use a signal, it just doens't get emitted when I resize my column. Any idea?
    I just finished building something close to yours and updating the second view with data from the selection of the first view works.

  8. #7
    Join Date
    Jul 2011
    Location
    Belgium
    Posts
    24
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Linking of 2 QTableViews

    Quote Originally Posted by thefatladysingsopera View Post
    I just finished building something close to yours and updating the second view with data from the selection of the first view works.
    Well, that's the point I think. The data get's updated. But it's just the view, the columns need to be 'linked' together so that when you change the first columns width, that same column should resize in the second view..

Similar Threads

  1. Linking With Qt VS Add in
    By rcjohns in forum Newbie
    Replies: 2
    Last Post: 14th March 2010, 13:42
  2. Linking to a DLL
    By JohnGaby in forum Newbie
    Replies: 1
    Last Post: 14th October 2009, 20:52
  3. Match Height between 2 Adjoining QTableViews
    By ChrisW67 in forum Qt Programming
    Replies: 0
    Last Post: 14th April 2009, 04:52
  4. Linking
    By ^NyAw^ in forum General Programming
    Replies: 7
    Last Post: 30th October 2008, 18:37
  5. dll linking
    By Project25 in forum Qt Programming
    Replies: 3
    Last Post: 12th July 2007, 08:39

Tags for this Thread

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.