PDA

View Full Version : Linking of 2 QTableViews



Taxi
3rd October 2011, 15:36
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

wysota
3rd October 2011, 16:41
Connect to the QHeaderView::sectionResized() signal of one table and adjust the size of the other table's headers.

thefatladysingsopera
3rd October 2011, 20:11
In the first view,you could have :


connect(ui.filesView->selectionModel(),
SIGNAL(currentRowChanged(const QModelIndex&,
const QModelIndex&)),
this, SLOT(updateFileView()));

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

ChrisW67
4th October 2011, 00:50
Seems odd to go to all this effort to duplicate the supplied selection highlighting.

Taxi
4th October 2011, 09:03
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:


QObject::connect(m_fileTableView->horizontalHeader(),SIGNAL(sectionResized(int,int,i nt)),m_selectionTableView,SLOT(onSectionResized(in t,int,int)));

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


QHeaderView* selectionHeader = m_selectionTableView->horizontalHeader();
if(selectionHeader)
return selectionHeader->resizeSection(index, newSize);
else
return ;

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


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.

thefatladysingsopera
4th October 2011, 09:29
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.
:)

Taxi
4th October 2011, 09:32
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..