gpt4 book ai didi

macos - 在 Qt 中组合工具栏和标题栏

转载 作者:行者123 更新时间:2023-12-04 17:01:27 35 4
gpt4 key购买 nike

如何在顶部栏中实现工具栏,例如 Tiled完成了吗?

Tiled
通常,工具栏如下所示:

enter image description here

示例代码当前如何:

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = nullptr) {
auto *tbar = new QToolBar();
tbar->addWidget(new QPushButton("Push Me"));
this->addToolBar(tbar);
}
};

最佳答案

如果你还在使用 Qt 4.x,你可以使用 setUnifiedTitleAndToolBarOnMac(bool set)包含在 QMainWindow 中的函数:

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = nullptr) {
auto *tbar = new QToolBar();
tbar->addWidget(new QPushButton("Push Me"));
this->addToolBar(tbar);
this->setUnifiedTitleAndToolBarOnMac(true); // activate Mac-style toolbar
}
};

另见: https://qt-project.org/doc/qt-4.8/qmainwindow.html#unifiedTitleAndToolBarOnMac-prop

关于macos - 在 Qt 中组合工具栏和标题栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16681965/

35 4 0