Simple table for a settings class
-
wrote on 26 Jul 2013, 19:46 last edited by
So i generally don't use the GUI much with qt, so i'm flat out confused with all the options. Basically all i need is a settings class to complete my little app.
there are tables, columns and all sorts of fun stuff. I'm not sure the easiest route to what i need.
All i need is two columns, the first column is locked to a label, the setting column is a editable short. Each row is a different setting.I'm looking at some settingseditor example and its not the simplest thing i've seen before... its difficult to break down the actual QTableView part of it.
-
Hi,
It all depends of the type of the settings, you could use a "QFormLayout":http://qt-project.org/doc/qt-4.8/qformlayout.html or "QGroupBox":http://qt-project.org/doc/qt-4.8/qgroupbox.html
Or associate a "QListWidget":http://qt-project.org/doc/qt-4.8/qlistwidget.html with a "QStackedWidget":http://qt-project.org/doc/qt-4.8/qstackedwidget.html
You'd have to tell a bit more of your needs or give an example of how you would like it to look
-
wrote on 26 Jul 2013, 20:12 last edited by
it can look this simple
| label | value |
| label | value |
| label | value |label is not editable, value is but has bounds because its a short
and it can be this simple to set up@
s = new setting()foreach(QHash<QString,short> pair, settingsList)
{
s.addSetting(pair.key(),pair.value());
}
@and maybe one signal
signal settingChanged(QString name, short val);we are limited by hardware this is why there are shorts, and it doesn't need to be pretty. I think there are too many options to make this easy for once.
edit: the only real requirement here is not to back the amount of settings we can use, or bake in any names into the gui. So as my list of settings grow i don't have to worry about this other than maybe sticking in a scroll bar
-
Then a QWidget with a QFormLayout using QSpinBox's limited to the range of short. For the possible scroll bar have a look at QScrollArea and you should be good to go
-
wrote on 26 Jul 2013, 22:05 last edited by
success! well almost, once i saw you mention QListWidget, i just made a table entry widget with a lineedit thats read only and a spin box.
add them to listwidget for great success. Only i can't get my list widget to resize at all.
@
QListWidget *listWidget = new QListWidget(this);
listWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);std::list<Setting> list = settings.listSettings(); foreach(Setting set, list) { QString entryName = set.c_str(); short val = settings.getSetting(set); SettingsEntry *e = new SettingsEntry(entryName, val); connect(e, SIGNAL(changed(QString,short)), this, SLOT(onSettingsChange(QString,short))); QListWidgetItem *i = new QListWidgetItem(); listWidget->addItem(i); listWidget->setItemWidget(i,e); }
@
-
Aren't you forgetting to listWidget in a layout ?
-
wrote on 26 Jul 2013, 22:10 last edited by
ok that was pretty stupid, the listwidget is useless now, adding a layout....
edit: wrong again, no scroll bar without the listWidget,, adding to layout..
-
wrote on 26 Jul 2013, 22:28 last edited by
huh now that it works it looks kind of shitty theres a lot of space inbetween all my options
-
You can take a look at the style sheet chapter to modify the aspect of your widget.
Or create a QStyledItemDelegate to modify the presentation
-
wrote on 27 Jul 2013, 22:53 last edited by
i think the style delegate may be a bit too much, i've found that I can change teh border and change the space between. Great an all but I seem to be missing a vertical scroll bar using this method.
Using a listwidget works better as its has more things set up but causes overlapping with my widgets...
oh well i'll just have to keep reading and messing with settings
1/10