在C++中,可以使用QFont
类和setFont()
函数来设置QGroupBox标题的字体为粗体。以下是一个示例代码:
#include <QApplication>
#include <QMainWindow>
#include <QGroupBox>
#include <QVBoxLayout>
#include <QLabel>
#include <QFont>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow window;
QGroupBox *groupbox = new QGroupBox("My Group Box");
QFont font("Arial", 12, QFont::Bold); // 创建一个粗体字体对象
groupbox->setFont(font); // 设置标题字体为粗体
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(new QLabel("Content of the group box"));
groupbox->setLayout(layout);
window.setCentralWidget(groupbox);
window.show();
return app.exec();
}
这个示例代码通过创建一个QFont
对象并设置其样式为粗体来实现标题字体的设置。可以根据需要调整字体名称、大小和样式。
内容由零声教学AI助手提供,问题来源于学员提问