PDA

View Full Version : Best Way for a dynamic Widget or adapting QListView, QListWidget?



Astronomy
17th February 2010, 11:20
Hi Everyone,

I want to Exclude several groups of Data. ( from a calculation...)
And i'am thinking about what the best way it will be, how to do it. I principal i intend to do something like this:
The range of the Wavelength to exclude should be selected in a QSpinBox: From and a QSpinBox To. and this should be stored somewhere.

1) Way i can try to edit the QSpinboxes, and with an Enter, a set of new QSpinboxes will be shown dynamically at runtime. (Maybe with new MyWidget...) The From - To -Data will be stored in an ascii file. because i need them to be available the next time the SW starts up. (without the white QListView in the picture below...)
Therefore i think i need to make my own Widget, as shown in the Picture.(actually in the pic there are several qt widgets..)
My Question here is: Whats the best way to implement this dynamically, and do it with some sliders? e.g. if i have 10 items how can i navigate through them?

2) Way I only have on pair of QSpinBoxes From To (already in the picture) and i try to get the Data in a QListView or QListWidget. Therefore i may have to subclass them to get my Data in there. like:


class CMyItem
{ // Wavelength to be excluded from Calculation..
public:
// Inline definition
CMyItem() { LowerLimit = 0.0; UpperLimit = 0.0; }
double LowerLimit;
double UpperLimit;
};

class CMyListView : public QListView
{
public:
CMyListView(QWidget *parent = 0);
// ~CMyQListView();

CMyItem MyItem;
};



But QListView has not something like addData() which i can trace. In the QListWidget class reference is a hint that:For a more flexible list view widget, use the QListView class with a standard model.

3) Way Something complete other?

I've tested both versions an didn't come far until now. And i'm asking what maybe will be more easier or elegant to try to implement? Or is there already something similar around in Qt?

I'm a little stucked what the best way will be :confused:
Many thanks for any suggestions
Astronomy

http://web143.login-6.loginserver.ch/lr/upload/Bildschirmfoto.png

axeljaeger
17th February 2010, 16:01
I understand your question as follows:

You have some data records and each record has a "wavelength".
You want to filter the records where the wavelength is between a certain range.
You want to display those records that match the filter.

Suggestion on how to implement this with Qt:

Create some kind of listmodel, either subclassing or use one of the existing ones that only display the data.
Implement the filtering using a QSortFilterProxyModel. Subclass QSortFilterProxyModel to match only rows that match you criteria: between upper and lower wavelength.

Make a structure like this: YourList => YorFilterProxy => QListView.

Astronomy
18th February 2010, 15:05
Hi Axel,
Yes u got me.
Thanks for the hints, especially QSortFilterProxyModel.
Until now i have stored my Data to Exclude in two QComboBoxes(double) and they are connected via the Index (per max-min Range per Index..). This is working but it looks badly *gg*. I'll try your Suggestion out. :)

Thanx
Astronomy