Simple table for a settings class

  • 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.

  • Lifetime Qt Champion


    It all depends of the type of the settings, you could use a "QFormLayout": or "QGroupBox":

    Or associate a "QListWidget": with a "QStackedWidget":

    You'd have to tell a bit more of your needs or give an example of how you would like it to look

  • 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)

    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

  • Lifetime Qt Champion

    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

  • 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();


  • Lifetime Qt Champion

    Aren't you forgetting to listWidget in a layout ?

  • 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..

  • huh now that it works it looks kind of shitty theres a lot of space inbetween all my options

  • Lifetime Qt Champion

    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

  • 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

Log in to reply