使用setWhatIsThis在Qt与QPushButton

Using setWhatIsThis in Qt with QPushButton

本文关键字:QPushButton Qt setWhatIsThis 使用      更新时间:2023-10-16

我需要显示一个"帮助文本"当鼠标在一个按钮,我谷歌和我尝试了一些代码,但徒劳的。

谁能给我纠正一下吗?
if (event->type() == QEvent::Enter)
{
    if (obj == q1)
    {
        iarm->printStatus("hi"); // For debugging
        QAction *newAct = new QAction(tr("&New"), this);
        newAct->setShortcut(tr("Ctrl+N"));
        newAct->setStatusTip(tr("Create a new file"));
        newAct->setWhatsThis(tr("Click this option to create a new file."));
    }
}

而不是通过QAction,只是使用你的QPushButton的(好吧,QWidget的真正)setToolTip(const QString &)

这将为您的按钮/小部件设置一个工具提示,当鼠标悬停在它上面时出现。这似乎是你想要的,而不是你现在想用的"这是什么"的信息。

你可以使用QpushButton的属性setToolTip (const QString &)同样的原因。这将显示你的帮助文本鼠标悬停在Qpushbutton。

对于智能文本,根据您的要求,您可以为工具提示设置样式表:-

QToolTip {color: #fff;background - color: # 000;边界:没有;}