如何解决当我使用Pango标记时,如何从MessageDialog中读取变量?
如何使用变量在messagedialog文本中使用pango标记
例如此代码
void usb_boot::creation(){
//Gtk::MessageDialog dialogue(*this,listeDeroulante.get_active_text());
std::string message("Type de formatage : " + type),type1,chemin1;
Gtk::MessageDialog *dialogue = new Gtk::MessageDialog("Résumé",true,Gtk::MESSAGE_QUESTION,Gtk::BUTTONS_YES_NO);
dialogue->set_title("Résumé");
dialogue->set_message("<span weight='bold'>message</span>",true);
dialogue->set_secondary_text("<b>listeDeroulante.get_active_text()</b>",true);
dialogue->set_default_response(Gtk::RESPONSE_YES);
int result = dialogue->run();
set_message
和set_secondary_text
必须打印变量,但只能“看到”单词。
有没有办法读取类似的变量?
解决方法
虽然std::stringstream
解决方案有效,但我建议通过std::string
的{{1}}使用简单的string concatenation:
operator+
使用此解决方案,无需引入额外的#include <gtkmm.h>
int main(int argc,char **argv)
{
auto app = Gtk::Application::create(argc,argv,"so.question.q63886899");
Gtk::Window w;
w.show_all();
{
// Unformatted messages:
std::string primaryMessage = "Some message...";
std::string secondaryMessage = "Some more message details...";
Gtk::MessageDialog dialog(w,"Message dialog",true,Gtk::MESSAGE_QUESTION,Gtk::BUTTONS_YES_NO);
dialog.set_title("Title");
// Add pango markup tags through string concatenation:
dialog.set_message("<span weight='bold'>" + primaryMessage + "</span>",true);
dialog.set_secondary_text("<b>" + secondaryMessage + "</b>",true);
dialog.run();
}
return app->run(w);
}
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。