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:
Code:
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->doubleSpinBox->installEventFilter(this);
QObjectList o_list = ui->doubleSpinBox->children();
for(int i = 0; i < o_list.length(); i++)
{
QLineEdit *cast
= qobject_cast<QLineEdit
*>
(o_list
[i
]);
if(cast)
cast->installEventFilter(this);
}
}
and
Code:
{
if(event
->type
() == QEvent::MouseButtonPress) {
Dialog mdialog;
mdialog.setModal(true);
mdialog.exec();
}
return false;
}
I am wondering if its possible to automate this part
Code:
ui->doubleSpinBox->installEventFilter(this);
//~~~~~~~~^
QObjectList o_list = ui->doubleSpinBox->children();
// ~~~~~~~~^
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
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
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,
_
Re: Dynamic Handling of Hundreds of UI elements
Quote:
Originally Posted by
anda_skoa
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
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,
_