Results 1 to 7 of 7

Thread: Widget Arrays?

  1. #1
    Join Date
    Jun 2008
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Widget Arrays?

    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?

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Widget Arrays?

    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.

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

    Default Re: Widget Arrays?

    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:

    Qt Code:
    1. class SubasterArray : public QWidget {
    2. Q_OBJECT
    3. public:
    4. SubmasterArray(int initialCount = 4, QWidget *parent = 0) : QWidget(parent) {
    5. QHBoxLayout *l = new QHBoxLayout(this);
    6. for(int i=0;i<initialCount;i++){
    7. QSlider *slid = new QSlider;
    8. l->addWidget(slid);
    9. m_groups << slid;
    10. }
    11. }
    12. int count() const { return m_groups.count(); }
    13. QSlider *sliderAt(int i) const { return m_groups.at(i); }
    14. QSlider *addSubmaster() {
    15. QSlider *slid = new QSlider;
    16. layout()->addWidget(slid);
    17. m_groups << slid;
    18. return slid;
    19. }
    20. void removeSubmaster(int i){
    21. if(i<0 || i>=m_groups.count()) return;
    22. delete m_groups[i];
    23. m_groups.removeAt(i);
    24. }
    25. private:
    26. QList<QSlider*> m_groups;
    27. };
    To copy to clipboard, switch view to plain text mode 

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

  4. #4
    Join Date
    Sep 2006
    Posts
    68
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Widget Arrays?

    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!

  5. #5
    Join Date
    Jun 2008
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget Arrays?

    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!

  6. #6
    Join Date
    Sep 2006
    Posts
    68
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Widget Arrays?

    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.

  7. #7
    Join Date
    Jun 2008
    Posts
    29
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget Arrays?

    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!

Similar Threads

  1. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  2. Custom widget
    By zorro68 in forum Qt Programming
    Replies: 7
    Last Post: 28th January 2008, 14:06
  3. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17:52
  4. Controlling which widget on top layer?
    By JonathanForQT4 in forum Qt Programming
    Replies: 6
    Last Post: 22nd March 2007, 14:27
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 14:16

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.