热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

qt中pushbutton样式表_QtQPushButton样式表悬停(QtQPushButtonstylesheethover)

QtQPushButton样式表悬停(QtQPushButtonstylesheethover)我有以下按钮样式表:QPushButton:hover{backgro

Qt QPushButton样式表悬停(Qt QPushButton stylesheet hover)

我有以下按钮样式表:

QPushButton:hover{

background: qlineargradient(x1 : 0, y1 : 0, x2 : 0, y2 : 1, stop : 0.0 #ffd9aa,

stop : 0.5 #ffbb6e, stop : 0.55 #feae42, stop : 1.0 #fedb74);

}

QPushButton {

border: 1px solid #6593cf;

border-radius: 2px;

padding: 5px 15px 2px 5px;

background: qlineargradient(x1 : 0, y1 : 0, x2 : 0, y2 : 1, stop : 0.0 #f5f9ff,

stop : 0.5 #c7dfff, stop : 0.55 #afd2ff, stop : 1.0 #c0dbff);

color: #006aff;

font: bold large "Arial";

height: 30px;

}

QPushButton:pressed {

background: qlineargradient(x1 : 0, y1 : 0, x2 : 0, y2 : 1, stop : 0.0 #c0dbff,

stop : 0.5 #cfd26f, stop : 0.55 #c7df6f, stop : 1.0 #f5f9ff);

padding-top: 2px;

padding-left: 3px;

}

QPushButton:on {

background: qlineargradient(x1 : 0, y1 : 0, x2 : 0, y2 : 1, stop : 0.0 #5AA72D,

stop : 0.5 #B3E296, stop : 0.55 #B3E296, stop : 1.0 #f5f9ff);

padding-top: 2px;

padding-left: 3px;

}

QPushButton:disabled {

background: transparent #e5e9ee;

padding-top: 2px;

padding-left: 3px;

color: black;

}

我有一个按钮。 当它被按下时,侧面小部件被调整大小。 因此按钮获得按下的样式,当我释放它时获得悬停样式。 此外,窗口小部件被调整大小并且按钮“跟随”窗口小部件。 问题是当我用鼠标进行一些移动时,按钮会保持悬停状态并丢失它。 这是来自qt的错误还是我在样式表代码中遗漏了一些东西。

我做了一个动画gif显示情况:

IIveC.gif

谢谢

I have the following pushbutton stylesheet:

QPushButton:hover{

background: qlineargradient(x1 : 0, y1 : 0, x2 : 0, y2 : 1, stop : 0.0 #ffd9aa,

stop : 0.5 #ffbb6e, stop : 0.55 #feae42, stop : 1.0 #fedb74);

}

QPushButton {

border: 1px solid #6593cf;

border-radius: 2px;

padding: 5px 15px 2px 5px;

background: qlineargradient(x1 : 0, y1 : 0, x2 : 0, y2 : 1, stop : 0.0 #f5f9ff,

stop : 0.5 #c7dfff, stop : 0.55 #afd2ff, stop : 1.0 #c0dbff);

color: #006aff;

font: bold large "Arial";

height: 30px;

}

QPushButton:pressed {

background: qlineargradient(x1 : 0, y1 : 0, x2 : 0, y2 : 1, stop : 0.0 #c0dbff,

stop : 0.5 #cfd26f, stop : 0.55 #c7df6f, stop : 1.0 #f5f9ff);

padding-top: 2px;

padding-left: 3px;

}

QPushButton:on {

background: qlineargradient(x1 : 0, y1 : 0, x2 : 0, y2 : 1, stop : 0.0 #5AA72D,

stop : 0.5 #B3E296, stop : 0.55 #B3E296, stop : 1.0 #f5f9ff);

padding-top: 2px;

padding-left: 3px;

}

QPushButton:disabled {

background: transparent #e5e9ee;

padding-top: 2px;

padding-left: 3px;

color: black;

}

I have a button. When it's pressed a side widget is resized. Thus the button gets the pressed style, when I release it gets the hover style. Furthermore the widget is resized and the button "follows" the widget. The problem is that the button keeps the hover state and loses it when I do some movement with the mouse. Is this a bug from qt or I miss something in the stylesheet code.

I did a animated gif showing the situation:

IIveC.gif

Thanks

原文:https://stackoverflow.com/questions/25318538

更新时间:2019-11-19 02:49

最满意答案

你可以说这是Qt中的一个错误。 我会说这是一种由正确逻辑引起的错误。 为自己判断。 Hover状态由WA_UnderMouse小部件属性定义。 此属性由应用程序设置:

if ((e->type() == QEvent::Enter || e->type() == QEvent::DragEnter) ...

widget->setAttribute(Qt::WA_UnderMouse, true);

else if (e->type() == QEvent::Leave || e->type() == QEvent::DragLeave)

widget->setAttribute(Qt::WA_UnderMouse, false);

QEvent::Enter和QEvent::Leave事件仅在应用程序从OS接收鼠标事件时发送。

您不移动鼠标,应用程序不会收到任何鼠标事件,因此WA_UnderMouse属性不会更改。

解决这个问题的方法之一是在移动按钮小部件时自己将Qt::WA_UnderMouse属性设置为正确的值。

You can say that it's a bug in Qt. I would say it's a kind of bugs caused by right logic. Judge for yourself. Hover state is defined by WA_UnderMouse widget attribute. This attribute is set by the application:

if ((e->type() == QEvent::Enter || e->type() == QEvent::DragEnter) ...

widget->setAttribute(Qt::WA_UnderMouse, true);

else if (e->type() == QEvent::Leave || e->type() == QEvent::DragLeave)

widget->setAttribute(Qt::WA_UnderMouse, false);

QEvent::Enter and QEvent::Leave events are only sent when the application receives mouse event from OS.

You don't move mouse, the application doesn't receive any mouse event and so WA_UnderMouse attribute is not changed.

One of the ways to fix that is to set Qt::WA_UnderMouse attribute to the right value by yourself when moving the button widget.

2014-08-15

相关问答

不要这么想,你可能会通过逐步完成绘图代码来找到某些东西。 但是样式表的解析和应用程序相当优化,并且使用了很多预处理。 我甚至不认为如果它实际设置在父项中,则可以访问小部件的样式表。 Don't think so, you might be able to find something by stepping through the drawing code. But the parsing and the application of stylesheets is pretty optimised

...

它似乎特定于您的平台。 有许多错误报告具有相同的错误。 但是尝试为您的应用设置cleanlooks样式。 像这样的东西: app = QtGui.QApplication(sys.argv)

#QCleanlooksStyle

app.setStyle('cleanlooks')

或者使用命令行: ./myapp -style cleanlooks

It seems that it is specific for your platform. There are many bug report

...

你可以说这是Qt中的一个错误。 我会说这是一种由正确逻辑引起的错误。 为自己判断。 Hover状态由WA_UnderMouse小部件属性定义。 此属性由应用程序设置: if ((e->type() == QEvent::Enter || e->type() == QEvent::DragEnter) ...

widget->setAttribute(Qt::WA_UnderMouse, true);

else if (e->type() == QEvent::Leave || e-

...

对于问题的第二部分:不要使用“平面”属性,而是修改样式表以实现平面外观,也许如下所示: QPushButton#pushButton {

background-color: #ffffff;

border: 0px;

}

/* ... plus the rest of your stylesheet ... */

关于“为什么不起作用”的部分? 根据我的经验,为窗口小部件混合样式表和非样式表单选项会产生许多难以解释的神秘效果。 我放弃了要求“为什么”。 For the seco

...

在命名对象之前,首先需要setObjectName(“somename”),然后objectName()将起作用,甚至更好 - findChild()或findChildren() 例 标题: QButton foo;

类: foo = new QButton();

foo.setObjectName("MySuperButton");

然后,最后在你的QSS .. #MySuperButton {

background: black;

}

这也与CSS类似 QButton#My

...

最后我得到了解决方案。 这个想法与CSS属性选择相同。 因此property_1 =“true”AND property_2 =“true”条件是: MyButton[property_1="true"][property_2="true"] { background-color: green; }

Finally I got the solution. The idea is the same as CSS attribute selection. Thus property_1="true

...

我不认为你可以搞乱边框或填充而不影响小部件的默认大小。 你可以设置min-width 。 从文档: If this property is not specified, the minimum width is derived based on the widget's contents and the style. QPushButton {

border-radius: 2px;

padding: 0.2em 0.2em 0.3em 0.2em;

border: 1px

...

当您使用setMenu()设置QPushButton的菜单时,菜单将继续作为其自己的实体存在,因此您将使用适当的选择器来定位QMenu对象本身。 QMenu支持盒子模型。 可以在此处找到一些示例样式。 When you set the menu for a QPushButton using setMenu(), the menu continues to exist as its own entity so you would target the QMenu object itself wit

...

好吧,我没有找到任何解释或建议,所以我自己找到了解决方案。 为了突出显示QWidgetAction按钮,我添加了动态属性,就像在下面的代码中构建按钮的地方一样: m_pasteButton->setProperty("mouseHover", false);

然后,在按钮上安装过滤器并捕获Enter和Leave事件以确定何时鼠标悬停: bool CustomWidgetAction::eventFilter(QObject* object, QEvent* event)

{

if (ob

...

正常状态按钮的样式: QPushButton

{

color: red;

}

“已禁用”状态按钮的样式: QPushButton:!enabled

{

color:blue;

}

这可能会解决您的问题 Style for the normal state button: QPushButton

{

color: red;

}

Style for the "Disabled" state button: QPushButton:!enabled

{

co

...



推荐阅读
  • 我正在尝试创建一个在单击按钮时出现的表单。这是输出: ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 使用HTML创建弹出框以便用户输入信息
    在做项目的过程中,我们时常需要进行一些弹框操作,比如在后台管理时需要进行的一些增删改操作,这个时候我们需要使用到弹框,或者在 ... [详细]
  • 用Vue实现的Demo商品管理效果图及实现代码
    本文介绍了一个使用Vue实现的Demo商品管理的效果图及实现代码。 ... [详细]
  • jQuery实现简单的动画效果及用法详解
    本文详细介绍了使用jQuery实现简单动画效果的方法,包括显示/隐藏、向上收缩/向下展开、淡入/淡出、自定义动画等。同时提供了具体的用法示例,并解释了参数的含义和使用技巧。通过本文的学习,读者可以掌握如何使用jQuery实现各种动画效果,为网页增添生动和互动性。 ... [详细]
  • 使用Flutternewintegration_test进行示例集成测试?回答首先在dev下的p ... [详细]
  • 本文由编程笔记#小编为大家整理,主要介绍了css回到顶部按钮相关的知识,希望对你有一定的参考价值。 ... [详细]
  • 人脸检测 pyqt+opencv+dlib
    一、实验目标绘制PyQT界面,调用摄像头显示人脸信息。在界面中,用户通过点击不同的按键可以实现多种功能:打开和关闭摄像头, ... [详细]
  • 当我在doWork方法中运行代码时,通过单击button1,进度条按预期工作.但是,当我从其他方法(即btn2,btn3)将列表传递给doWork方法时,进度条在启动后会跳转到10 ... [详细]
  • 面试中2次被问到过这个知识点,实际开发中,应用事件委托也比较常见。JS中事件委托的实现主要依赖于事件冒泡。那什么是事件冒泡?就是事件从最深 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • 使用圣杯布局模式实现网站首页的内容布局
    本文介绍了使用圣杯布局模式实现网站首页的内容布局的方法,包括HTML部分代码和实例。同时还提供了公司新闻、最新产品、关于我们、联系我们等页面的布局示例。商品展示区包括了车里子和农家生态土鸡蛋等产品的价格信息。 ... [详细]
  • 本文整理了常用的CSS属性及用法,包括背景属性、边框属性、尺寸属性、可伸缩框属性、字体属性和文本属性等,方便开发者查阅和使用。 ... [详细]
  • 基于jquery实现简单的分页控件_jquery
    前台分页控件有很多,这里分享我的分页控件pagination.js1.0版本,该控件基于jquery。先来看一下预览效果: ... [详细]
  • vue扫描二维码
    本地要用localhost。发布之后要用https的才可以看到。(你的设备也必须有摄像头)切记卡号 ... [详细]
author-avatar
唉尼宝宝_586
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有