在我的文本编辑器应用程序中,我将用户字体格式选择保存为首选项。
信号和槽首先在构造函数中设置,然后读取首选项,如下代码所示:
构造函数:
boldAction->setCheckable(true);
italicAction->setCheckable(true);
underlineAction->setCheckable(true);
fontSizeSelector->setCheckable(false);
connect(boldAction,SIGNAL(changed()),this,SLOT(bold()));
connect(italicAction,SIGNAL(triggered()),this,SLOT(italic()));
connect(underlineAction,SIGNAL(triggered()),this,SLOT(underline()));
读取用户首选项():
void TextEditor::readUserPreferences()
{
QSettings userPreferences(QSettings::NativeFormat,QSettings::UserScope,ORGANIZATION_TITLE,APPLICATION_TITLE);
this->boldAction->setChecked( userPreferences.value("appearance/bold").toBool() );
this->italicAction->setChecked( userPreferences.value("appearance/italic").toBool() );
this->underlineAction->setChecked( userPreferences.value("appearance/underline").toBool());
//other code.
}
现在,在 readPreferences 函数中,什么时候boldAction->setChecked(true);
,文本不应该变成粗体,因为已经定义了信号和槽机制吗?如果是这样,那为什么它不能在我的应用程序上运行?粗体功能本身工作得很好。
有没有比我正在做的更好的方法呢?谢谢你的帮助