Results 1 to 3 of 3

Thread: Keeping track of an unknown number of widgets

  1. #1
    Join Date
    Nov 2019
    Location
    Lyon, France
    Posts
    18
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Keeping track of an unknown number of widgets

    Hi!

    From my Maindow, I want the user to be able to open a setting window which will display x widget (check boxes).
    In short, the user will load a data file, with each type of data being associated with a code. And in this setting window, he will be able to choose which data to display or not by checking or unchecking the check boxes. Thing is, I cannot determine how much data types there will be before loading the file.

    I did try different methods and succeeded in creating an unknown number of widget when the window open.
    But I didn't find a way to keep track of them to know which one are checked or not. Or rather, I didn't find a way to differentiate all of them an determine which one has its state changed.
    Do you know a method for that?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,238
    Thanks
    303
    Thanked 865 Times in 852 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Keeping track of an unknown number of widgets

    It is not clear to me exactly what you are trying to do. It sounds like you are confusing the user action of selecting which widgets to create with the action of actually creating them. To select the widgets to create, all you need is a dialog with a list widget with check boxes. When the dialog is closed, you examine the entries in the list to see which ones to create.

    If these widgets will be created by the MainWindow (or some other widget) in your application, then your MainWindow needs a data structure (QVector, QList, QMap, etc.) which can store the pointers to these new widgets as they are created. If the user can close these widgets at any time, then your MainWindow class needs a slot that can be connected to each widget's destroyed() signal so the MainWindow can remove the pointer from the data structure.

    If each of these widgets is displaying some data that is held in your program, then you need a general mechanism to tell the widgets when the data's state has changed. In my applications, I usually have a "document" class that holds all of the program data. When this data is modified, the document class emits one signal (documentChanged(), say) with a flags argument that tells which data property(ies) were changed. Each display widget is connected to this signal when it is created, and in its slot to handle the signal will look at the flags argument to see if it is interested in that change. If it is, it updates its display.

    If this doesn't help, maybe you can give some more detail about what you are trying to do.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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

    monkiecreature (21st May 2020)

  4. #3
    Join Date
    Nov 2019
    Location
    Lyon, France
    Posts
    18
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Keeping track of an unknown number of widgets

    You understood well.
    I did as you said and put my checkbox in a Vector as I create them, and then send a signal to recover their individual state. It seems to work well! I will do some more tests to see
    I was also thinking of doing a "document" class as you said, maybe it would be easier with that.
    Thanks!

Similar Threads

  1. Is there a limit to number of widgets on a gui page?
    By emp1953 in forum Qt Programming
    Replies: 3
    Last Post: 18th June 2017, 19:06
  2. Replies: 1
    Last Post: 5th March 2012, 06:34
  3. how to set unknown number of dynamic properties
    By rashmi in forum Qt Programming
    Replies: 0
    Last Post: 15th March 2011, 09:07
  4. Upper limit on number of widgets?
    By jdiewald in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2008, 23:00
  5. Keeping track of columns in custom models
    By darkadept in forum Qt Programming
    Replies: 1
    Last Post: 28th February 2008, 20:29

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.