QT QMenu下拉菜单实现

QT QMenu下拉菜单实现

点击QPushButton弹出下拉菜单

样式效果

类似QT下拉菜单效果
类似QT下拉菜单效果
在这里插入图片描述

代码

QPushButton *m_pSetButton            = new QPushButton(this);
 m_pSetButton->setIcon(QIcon(":/resource/mainimage/main_set.png"));
    m_pSetButton->setStyleSheet(QString("QPushButton::menu-indicator{image:none;}"
                                        "QPushButton{border-style: none;}"
                                        "QPushButton:hover{background-color:lightgray; color: white;}"
                                        "QPushButton:pressed{background-color:rgb(85, 170, 255); border-style: inset;}"));
    m_pSetButton->setCursor(QCursor(Qt::PointingHandCursor));
    m_pSetButton->setFixedHeight(35);
    m_pSetButton->setFixedWidth(35);
    
   QMenu *setUpMenu = new QMenu();
    QAction *networkAction = new QAction(setUpMenu);
    QAction *changePwAction = new QAction(setUpMenu);
    QAction *aboutAction = new QAction(setUpMenu);
    networkAction->setIcon(QIcon(":/resource/mainimage/main_set_net.png"));
    changePwAction->setIcon(QIcon(":/resource/mainimage/main_set_password.png"));
    aboutAction->setIcon(QIcon(":/resource/mainimage/main_set_about.png"));
    networkAction->setText(tr("  网络设置"));
    changePwAction->setText(tr("  密码修改"));
    aboutAction->setText(tr("  About RPMS..."));

    setUpMenu->addAction(networkAction);
    setUpMenu->addAction(changePwAction);
    setUpMenu->addAction(aboutAction);

    setUpMenu->setWindowFlags(setUpMenu->windowFlags() | Qt::FramelessWindowHint);
    setUpMenu->setAttribute(Qt::WA_TranslucentBackground);
    setUpMenu->setStyleSheet(" QMenu {border-radius:5px;font-family:'Arial';font-size:16px;}"
                     " QMenu::item {height:35px; width:120px;padding-left:25px;border: 1px solid none;}"
                     "QMenu::item:selected {background-color:rgb(0,120,215);\
                      padding-left:25px;border: 1px solid rgb(65,173,255);}");
    m_pSetButton->setMenu(setUpMenu);
    m_pSetButton->show();

//相关槽函数实现
    connect(networkAction,&QAction::triggered, this,&RPMSystem::slot_ShowNetWorkSetUI);
    connect(changePwAction,&QAction::triggered, this,&RPMSystem::slot_ShowChangePwUI);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值