Results 1 to 5 of 5

Thread: Dynamic Handling of Hundreds of UI elements

  1. #1
    Join Date
    Feb 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Dynamic Handling of Hundreds of UI elements

    Ok so here is what I've got... doubleSpinBox - doubleSpinBox_312. I made them all read only, I only want them the to be edited from within 1 dialog. Ive made one of them clickable through an eventFilter:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. ui->doubleSpinBox->installEventFilter(this);
    7. QObjectList o_list = ui->doubleSpinBox->children();
    8. for(int i = 0; i < o_list.length(); i++)
    9. {
    10. QLineEdit *cast = qobject_cast<QLineEdit*>(o_list[i]);
    11. if(cast)
    12. cast->installEventFilter(this);
    13. }
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. bool MainWindow::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. if(event->type() == QEvent::MouseButtonPress)
    4. {
    5. Dialog mdialog;
    6. mdialog.setModal(true);
    7. mdialog.exec();
    8. }
    9. return false;
    10. }
    To copy to clipboard, switch view to plain text mode 

    I am wondering if its possible to automate this part

    Qt Code:
    1. ui->doubleSpinBox->installEventFilter(this);
    2. //~~~~~~~~^
    3. QObjectList o_list = ui->doubleSpinBox->children();
    4. // ~~~~~~~~^
    To copy to clipboard, switch view to plain text mode 

    and to make sure I can return a value to a function that corresponds to what spinbox has been selected so that the dialog can return the new value to the appropriate field.

    I really like the parameters and the look that the spinbox with no arrows gives so that's how I arrived at this juncture. Perhaps this more a C++ question than a Qt question, in any event IDK cause I'm a n00b.

    Qt 5

    preemptive thank you
    Last edited by mrsurge; 7th February 2016 at 23:23.

  2. #2
    Join Date
    Mar 2015
    Posts
    4
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic Handling of Hundreds of UI elements

    Hi
    you could find all QDoubleSpinBox in mainwindow and then loop them
    and do the setting of filter on each.

    QList<QDoubleSpinBox *> spins = MainWindow->findChildren<QDoubleSpinBox *>();

    http://doc.qt.io/qt-5/qobject.html#findChildren
    Last edited by Metavoid; 8th February 2016 at 08:19.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic Handling of Hundreds of UI elements

    Derive from QDoubleSpinBox, implement the customization, use your spinbox instead of the default one.

    Then you don't have to do anything in MainWindow::MainWindow() other then calling setupUi();

    Cheers,
    _

  4. #4
    Join Date
    Feb 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Dynamic Handling of Hundreds of UI elements

    Quote Originally Posted by anda_skoa View Post
    Derive from QDoubleSpinBox, implement the customization, use your spinbox instead of the default one.

    Then you don't have to do anything in MainWindow::MainWindow() other then calling setupUi();

    Cheers,
    _
    maybe you can go into greater detail

    <-----n00b

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic Handling of Hundreds of UI elements

    1) derive a custom class from QDoubleSpinBox
    2) implement the event filter in that class and install it on "this" and on the line edit (you have direct access to the line edit through a protected method declared in the base class)
    3) Use designer's "promote widget" function to replace the QDoubleSpinBoxes with your class.

    Cheers,
    _

Similar Threads

  1. Change state on dynamic elements.
    By Binpix in forum Qt Quick
    Replies: 5
    Last Post: 1st October 2013, 23:20
  2. Replies: 0
    Last Post: 29th March 2012, 19:56
  3. Replies: 3
    Last Post: 26th July 2011, 19:11
  4. Replies: 1
    Last Post: 20th January 2011, 17:17
  5. Qt and C++ dynamic memory handling...
    By giowck in forum Newbie
    Replies: 6
    Last Post: 18th November 2009, 19:50

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.