setStyleSheet(styleSheet); connect(m_bClientsWindow, &QPus...-QT开发中文网" />

QT开发中文网

QWidgetAction* m_showClientsWindow = new QWidgetAction(this); QPushButton* m_bClientsWindow = new QPushButton(this); m_bClientsWindow->setText("Clients"); m_bClientsWindow->setStyleSheet(styleSheet); connect(m_bClientsWindow, &QPus...

根据你提供的代码,你创建了两个菜单项,并将它们添加到菜单栏中。当点击这些按钮时,会触发相应的槽函数。

代码看起来没有问题,如果想要实现按钮被选择后变灰的效果,你需要在样式表styleSheet中使用:pressed伪类选择器而不是:clicked。修改后的代码如下:

QString styleSheet = "QPushButton:pressed {"
                     "background-color: gray;"
                     "padding-top: 2px;"
                     "}";

QWidgetAction* m_showClientsWindow = new QWidgetAction(this);
QPushButton* m_bClientsWindow = new QPushButton(this);
m_bClientsWindow->setText("Clients");
m_bClientsWindow->setStyleSheet(styleSheet);
connect(m_bClientsWindow, &QPushButton::clicked, this, &MainWindow::s_menu_Clients);
m_showClientsWindow->setDefaultWidget(m_bClientsWindow);
this->menuBar()->addAction(m_showClientsWindow);

QWidgetAction* m_showESP32sWindow = new QWidgetAction(this);
QPushButton* m_bESP32sWindow = new QPushButton(this);
m_bESP32sWindow->setText("ESP32s");
m_bESP32sWindow->setStyleSheet(styleSheet);
connect(m_bESP32sWindow, &QPushButton::clicked, this, &MainWindow::s_menu_ESP32s);
m_showESP32sWindow->setDefaultWidget(m_bESP32sWindow);
this->menuBar()->addAction(m_showESP32sWindow);

这样修改后,当按钮被按下时,其背景颜色会变为灰色。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:setStyleSheet(styleSheet); connect(m_bClientsWindow, &QPus...">https://qt.0voice.com/?id=9111

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?