PDA

View Full Version : dynamic Handling of Hundreds of UI elements



mrsurge
8th February 2016, 02:41
Ok so here is what I've got... doubleSpinBox to 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:



MainWindow::MainWindow(QWidget *parent) :
QMainWindow(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



bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::MouseButtonPress)
{
Dialog mdialog;
mdialog.setModal(true);
mdialog.exec();
}
return false;
}


I am wondering if its possible to automate this part



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

Metavoid
8th February 2016, 08:21
http://www.qtcentre.org/threads/65146-Dynamic-Handling-of-Hundreds-of-UI-elements