qt+MacOS环境下添加标题栏和工具栏

1、.pro文件添加

macx: QT += macextras

2、合并标题栏、工具栏

    //合并标题栏和工具栏
    auto *tbar = new QToolBar();
    tbar->addWidget(new QPushButton("Btn"));
    this->addToolBar(tbar);
    this->setUnifiedTitleAndToolBarOnMac(true); // activate Mac-style toolbar

注意:全屏之后若还是需要显示工具栏 需设置相关属性

3、添加标题图标

    //添加ToolBar
    QMacToolBar *m_toolBar = new QMacToolBarz(this);
    QIcon qtIcon(QStringLiteral(":qtlogo.png"));

    QMacToolBarItem *item1 = m_toolBar->addItem(qtIcon, QStringLiteral("title_1"));
    connect(item1, &QMacToolBarItem::activated,[=](){ qDebug() << "test ";});
    
    QMacToolBarItem *item2 = m_toolBar->addItem(qtIcon, QStringLiteral("title 2"));
    connect(item2, &QMacToolBarItem::activated, [=](){});

    QMacToolBarItem *item3 = m_toolBar->addItem(qtIcon, QStringLiteral("title 3"));
    connect(item3, &QMacToolBarItem::activated, [=](){});
    
    QMacToolBarItem *item4 = m_toolBar->addItem(qtIcon, QStringLiteral("title 4"));
    connect(item4, &QMacToolBarItem::activated, [=](){});
    m_toolBar->addSeparator();
    
    QMacToolBarItem *item11 = m_toolBar->addItem(qtIcon, QStringLiteral("title 5"));
    connect(item11, &QMacToolBarItem::activated,  [=](){});

    m_toolBar->attachToWindow(this->window()->windowHandle());

运行示意图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值