qmenubar 添加按钮_将自定义小部件添加到QMenuBar

本文介绍了如何在Qt4中为QMenuBar添加自定义小部件,由于Qt4不再支持直接插入QWidget,作者通过创建一个继承自QWidgetAction的类来实现此功能。代码示例中展示了如何创建和添加此类到菜单栏,但遇到了添加无效的问题,怀疑可能是Qt4的一个bug。
摘要由CSDN通过智能技术生成

Qt3 used to provide QMenuBar::insertItem with QWidget* parameter. This way any custom widget could be added to menu bar - for example a clock-widget.

In Qt4 there is no such overloaded method. What would be the best way to reach the same goal - adding custom widgets to a menu bar? The custom widgets should be integrated in the layout of menu bar.

Does anyoune knows the background, why this overload of insertItem was removed in Qt4 API?

Best regards.

解决方案

Sorry Javier for short comments. Every time I intended to break a line, the comment was submitted :-(

I tried this code in a project created with QtCreator:

class MyWidgetAction : public QWidgetAction

{

public:

MyWidgetAction( QObject * parent ) :QWidgetAction ( parent )

{

}

void releaseWidget ( QWidget * widget )

{<

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值