QT开发中文网

QPushButton 添加到QGridlayout后 不显示三态

QPushButton 默认情况下是支持三态的,但是在添加到 QGridLayout 时可能出现不显示三态的情况。这通常是由于在设置 QPushButton 的样式时没有正确设置三态的背景。

解决方法:

  1. 在设置 QPushButton 样式时,确保为每个状态设置了背景
QPushButton {
    background-color: #e0e0e0; /* 正常状态背景 */
}

QPushButton:hover {
    background-color: #f5f5f5; /* 悬停状态背景 */
}

QPushButton:pressed {
    background-color: #d2d2d2; /* 按下状态背景 */
}
  1. 如果仍然无法显示三态,则可以尝试调用 setAutoFillBackground(true) 方法来启用自动填充背景色。
QPushButton *button = new QPushButton("Button");
button->setAutoFillBackground(true);

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://qt.0voice.com/?id=863

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

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

联系我们

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

微信号:3007537140

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

关注我们
x

注册

已经有帐号?