#include <QMenu>
#include <QAction>
#include <QSettings>
#include <QApplication>
int main(int argc, char *argv[])
{
QMenu menu
("Position Menu");
settings->beginGroup("Position");
bool up = settings->value("up", false).toBool();
bool right = settings->value("right", false).toBool();
bool down = settings->value("down", false).toBool();
bool left = settings->value("left", false).toBool();
settings->endGroup();
QAction* up_action
= menu.
addAction("up");
up_action->setCheckable(true);
up_action->setChecked(up);
QAction* right_action
= menu.
addAction("right");
right_action->setCheckable(true);
right_action->setChecked(right);
QAction* down_action
= menu.
addAction("down");
down_action->setCheckable(true);
down_action->setChecked(down);
QAction* left_action
= menu.
addAction("left");
left_action->setCheckable(true);
left_action->setChecked(left);
menu.show();
a.connect(&menu, SIGNAL(aboutToHide()), SLOT(quit()));
int ret = a.exec();
up = up_action->isChecked();
right = right_action->isChecked();
down = down_action->isChecked();
left = left_action->isChecked();
settings->beginGroup("Position");
settings->setValue("up", up);
settings->setValue("right", right);
settings->setValue("down", down);
settings->setValue("left", left);
settings->endGroup();
return ret;
}
#include <QMenu>
#include <QAction>
#include <QSettings>
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMenu menu("Position Menu");
QSettings* settings = new QSettings("settings.ini", QSettings::IniFormat, &a);
settings->beginGroup("Position");
bool up = settings->value("up", false).toBool();
bool right = settings->value("right", false).toBool();
bool down = settings->value("down", false).toBool();
bool left = settings->value("left", false).toBool();
settings->endGroup();
QAction* up_action = menu.addAction("up");
up_action->setCheckable(true);
up_action->setChecked(up);
QAction* right_action = menu.addAction("right");
right_action->setCheckable(true);
right_action->setChecked(right);
QAction* down_action = menu.addAction("down");
down_action->setCheckable(true);
down_action->setChecked(down);
QAction* left_action = menu.addAction("left");
left_action->setCheckable(true);
left_action->setChecked(left);
menu.show();
a.connect(&menu, SIGNAL(aboutToHide()), SLOT(quit()));
int ret = a.exec();
up = up_action->isChecked();
right = right_action->isChecked();
down = down_action->isChecked();
left = left_action->isChecked();
settings->beginGroup("Position");
settings->setValue("up", up);
settings->setValue("right", right);
settings->setValue("down", down);
settings->setValue("left", left);
settings->endGroup();
return ret;
}
To copy to clipboard, switch view to plain text mode
Bookmarks