QT help button 和 setWhatsThis

来源:互联网 发布:mac 网络拓扑图软件 编辑:程序博客网 时间:2024/06/10 22:50

学习自《Foundations of Qt Development》


自定义窗口显示按钮: 帮助按钮和关闭按钮。

setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowContextHelpButtonHint);

Qt::CustomizeWindowHint用于将默认的按钮设置去除。或运算将关闭按钮和帮助按钮加入到对话框中。
设置两个checkBox的提示信息:

ui->checkBox->setWhatsThis(QObject::tr("this is a statement using <i>QObject::tr</i> for checkBox."));ui->checkBox_2->setWhatsThis(QObject::tr("<p style='white-space:pre'>this is a statement using <i>QObject::tr</i> "                                         "for checkBox.</p>"));

之后,点击窗口的帮助按钮,打开what‘s this mode。光标移动到widget上就能显示出提示信息。
使用HTML标记 white-space:pre可以取消自动换行。

关键code:

Dialog::Dialog(QWidget *parent) :    QDialog(parent),    ui(new Ui::Dialog){    setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowContextHelpButtonHint);    ui->setupUi(this);    ui->checkBox->setWhatsThis(QObject::tr("this is a statement using <i>QObject::tr</i> for checkBox."));    ui->checkBox_2->setWhatsThis(QObject::tr("<p style='white-space:pre'>this is a statement using <i>QObject::tr</i> "                                             "for checkBox.</p>"));/*white-space:normal | pre | nowrap | pre-wrap | pre-line默认值:normal取值:normal:    默认处理方式。pre:    用等宽字体显示预先格式化的文本,不合并文字间的空白距离,当文字超出边界时不换行。可查阅pre对象nowrap:    强制在同一行内显示所有文本,直到文本结束或者遭遇br对象。pre-wrap:    用等宽字体显示预先格式化的文本,不合并文字间的空白距离,当文字碰到边界时发生换行。pre-line:    保持文本的换行,不保留文字间的空白距离,当文字碰到边界时发生换行。*/}

让人奇怪的是,同一份代码,在环境CentOS i686, Qt Creator 2.8.1, Based on Qt 5.1.1 (GCC 4.6.1, 32 bit) 下窗口显示不出帮助按钮(那个问号按钮)。而在win7, Qt Creator 4.2.1, Based on Qt 5.8.0 (MSVC 2015, 32 bit)下则正常运行。低版本的qt真有那么多的问题吗?

在CentOS i686, Qt Creator 2.8.1, Based on Qt 5.1.1 (GCC 4.6.1, 32 bit) 下的关键代码:
setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowContextHelpButtonHint);
// Qt::WindowSystemMenuHint);

原创粉丝点击