QToolBar增加上去的按钮,按钮间的间距如何控制?

中才德创 中才德创 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
MyToolBar是“class MyToolBar : public QToolBar”的一个子类。

当我将按钮,用
CreateToolItems("text1", "image1");
CreateToolItems("text2", "image2");
加载了两个按钮时,发现:

它们的间距是1个像素。(windows下)

它们的间距是4个像素。(MAC下)

我想让它们的间距固定下来,不随操作系统而变,当如何去做?
void MyToolBar::CreateToolItems(QString strText, QString strImage)
{
qDebug ("%d: %s: %s Enter", __LINE__, __FILE__, __FUNCTION__);

QAction *pActionToolbar = addAction(strText);

if (NULL != pActionToolbar)
{
QWidget *pWidget = widgetForAction(pActionToolbar);
if (NULL != pWidget)
{
pWidget->setFixedSize(132, 132);
}

pActionToolbar->setIconText(strText);
QString strImagePath = m_strAppPath + "/" + strImage;
pActionToolbar->setIcon(QIcon(QPixmap(strImagePath)));
}

qDebug ("%d: %s: %s Exit", __LINE__, __FILE__, __FUNCTION__);
}
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
中才德创
Qt 21,503 成员 26,693 内容