为什么Qt信号与槽设置斜体失败?

img

img

img

下斜线是可以设置成功的,为什么斜体和加粗点击却没有用呢?是因为setBold和setItalic函数的原因吗?

查了一下文档,有可能不生效:

void QFont::setBold(bool enable)
If enable is true sets the font's weight to QFont::Bold; otherwise sets the weight to QFont::Normal.
For finer boldness control use setWeight().
Note: If styleName() is set, this value may be ignored, or if supported on the platform, the font artificially embolded.

因为你三个函数里用了三个不同font对象,要想全选都有,就需要font在你函数或者类的全局起作用,意思就是只建立一个font对象,然后三个函数都操作这同一个对象