PDA

View Full Version : Widget Arrays?



sekatsim
10th June 2008, 21:39
I'm developing an application that controls a series of theatrical lights via DMX. As it stands, for testing purposes, I've placed 8 "submasters". Each submaster has a slider, to set the brightness of the light, as well as three buttons that do other functions, and a combobox that displays a numeric representation of the value.

The code to handle just these eight submasters, especially now that I'm allowing the user to adjust values and operate buttons via joystick, is growing considerably large. In the final product, I am going to need to have around thirty six of these submasters. Which means for every event where I need to get / refresh one specific slider, I end up having to write out If statements for All of the sliders.

Ideally what I would really like would be to have some way of creating (even automatically, if possible.. that way the user can specify the number of subs) these submasters, and assigning them all names independently of their qobject names. That way, instead of

lx1->setvalue(curValue[1]);
lx2->setvalue(curValue[2]);

etc, for every slider
I could just use something like

for (i < 36; i++){
submaster[i].slider->setvalue(curValue[i];
}


Any thoughts?

JimDaniel
10th June 2008, 21:53
I think I understand what you're wanting...

Create your own SubMaster class that inherits from QWidget, and inside there put all the sliders, buttons, comboboxes you want, then you can treat that as one object.

From there, you just create a QList (or an array or whatever) of all your SubMaster objects. Then you can refer to each submaster by index, like you you are wanting. You can do even better if you implement signals and slots to pass that information.

Also, be aware of QSignalMapper, which sometimes helps in situations like this.

wysota
10th June 2008, 21:59
I'd suggest creating a custom widget where you could add or delete submasters on the fly. It should take you no more than an hour to implement such a class. Here is a stub to start with:


class SubasterArray : public QWidget {
Q_OBJECT
public:
SubmasterArray(int initialCount = 4, QWidget *parent = 0) : QWidget(parent) {
QHBoxLayout *l = new QHBoxLayout(this);
for(int i=0;i<initialCount;i++){
QSlider *slid = new QSlider;
l->addWidget(slid);
m_groups << slid;
}
}
int count() const { return m_groups.count(); }
QSlider *sliderAt(int i) const { return m_groups.at(i); }
QSlider *addSubmaster() {
QSlider *slid = new QSlider;
layout()->addWidget(slid);
m_groups << slid;
return slid;
}
void removeSubmaster(int i){
if(i<0 || i>=m_groups.count()) return;
delete m_groups[i];
m_groups.removeAt(i);
}
private:
QList<QSlider*> m_groups;
};

You could put it all inside a QScrollArea to have the groups scrollable.

December
12th June 2008, 13:33
Funny, I did the same about a year ago, but mine was actually with Playbacks running scenes or Sequences. I had a flash button at the bottom, a go button and a select button at the top.

I ended up doing it exactly how JimDaniel suggested, and it worked perfectly. I also had a pointer to the DMX scene or Sequence of Scenes stored in each fader Class, so from there I could display the name of the Scene / Sequence and which cue it was currenltly on in a QString at the top.

This made it really easy to keep the faders on screen but allow the user to Assign different cues to them.

Ooh, and did you know that the WholeHog3 software is written in QT, obviously QT is ideal for this kind of stuff!

sekatsim
12th June 2008, 22:11
December: Would you mind showing me your sources concerning the custom widget? I like the idea a lot, but this being my first project with Qt, I'm having a hard time getting it to work properly

Thanks!

December
13th June 2008, 02:45
Probably not a good idea, since I was also learning QT at the time and I'm sure I made a ton of mistakes and did things the wrong way.. but I will look for it and see how bad it is.

You may want to check this project out: http://qlc.sourceforge.net/index.php?doc=Features

It's Lighting control software written in QT, and they have some faders. Not looked at the source, but I expect you could some ideas from there.

Give me a couple of days to look for mine, I'm out on the road at the moment and it would be on my desktop at home.

sekatsim
13th June 2008, 02:57
Okay, thank you for the link, I'll see what I can make of it.

I have the day off sunday, so I was going to try and collect all of my notes and see if I can make something workable. If you could send me a few snippets by then, even if it's not the most elegant, I think it'd help quite a bit. My email is sekatsim @ gmail.com, if that helps any.

Thanks again!