qt中设置菜单高度

如题所示,我建立一个菜单,代码如下,但是菜单项的高度太小了,
    {
        popupMenu = new QMenu(this); 
    QAction *action1 = new QAction(tr("&New1"), this);
    QAction *action2 = new QAction(tr("&New2"), this);
    QAction *action3 = new QAction(tr("&New3"), this);
    QAction *action4 = new QAction(QIcon("./load.png"), tr("Bookstore"), this);
    popupMenu->addAction(action1);
    popupMenu->addAction(action2);
    popupMenu->addAction(action3);
    popupMenu->addAction(action4);
        popupMenu->exec();
        }

我用如下的方法设置菜单项的高度,但是都不行:
popupMenu->setFixedHeight(300);//这样只把菜单变大了,action还是那么小
popupMenu->setStyleSheet("QMenu::item { min-height: 100px }");//不好用?

究竟如何才好呢?


感谢大家的热心解答,我把我的收获贴在下面:
首先是简单的方法:
popupMenu->setStyleSheet("QMenu::item{ padding:100px;}");
这一句话就够。

其次使用QWidgetAction:
1)首先
class MyMenuItem:public QWidget
{
    Q_OBJECT
    public:
    MyMenuItem(QWidget *parent)
    {
        new QLabel("test",this);
    }
};
2)其次:
    MyMenuItem *item1 = new MyMenuItem(this);
    item1->setFixedSize(100,100);//这里可以设置大小
    QWidgetAction *action1 = new QWidgetAction(popupMenu);
    action1->setDefaultWidget(item1);
    MyMenuItem *item2 = new MyMenuItem(this);
    QWidgetAction *action2 = new QWidgetAction(popupMenu);
    action2->setDefaultWidget(item2);
    MyMenuItem *item3 = new MyMenuItem(this);
    QWidgetAction *action3 = new QWidgetAction(popupMenu);
    action3->setDefaultWidget(item3);

 

你可能感兴趣的:(qt)