问题标签 [qtoolbutton]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
qt - QStyleSheet - setting border-image for button also sets background image for its tooltip
I'm having a problem with setting the border-image property of a QToolButton (later on also of a QPushButton but I assume the problem will occur there too). Each of my custom buttons (inheriting from QToolButton and QPushButton respectively) has to have 3 states - inactive, running and error.
Inactive:
Running:
Error:
where self.cornerRadius is some number used to determine the roundness of my buttons in pixels and self.icon is an icon I have retrieved from somewhere.
All I do in my button's constructor (among other simple initializations) is
The clicked() signal of the button is connected to a slot in the same class where the state is changed (along with the style using self.setStyleSheet(...)) in respect to what the system's new state is.
For some unknown reason my tooltip receives the style changes of the button it "belongs to":
I've double-checked the Qt documentation and I see no reason that will explain this behaviour. I do NOT want to change the tooltip's style at all. Any ideas how to fix this?
qt - 如何使用 C++ 获取 QT-toolButton/pushButton 的背景颜色
相关问题:
如何获取小部件背景QColor
QWidget::palette().color(QWidget::backgroundRole())
解决问题的方法至少有3种:
更新:对不起,我犯了一些错误,以下两种方法都很好。
原始问题:
我努力了
和
都得到了QColor(ARGB 1, 0.941176, 0.941176, 0.941176),不是我想要的正确颜色。
背景颜色是通过编辑设置的mainwindow.ui,将toolButton的样式表更改为background-color: rgb(255, 170, 255);
对于 pyQt,请参见此处如何在 PyQt 中获取按钮或标签(QPushButton、QLabel)的背景颜色
qt - 如何通过样式表为每个 QActions 设置图标,这些 QActions 被添加到一个 QToolButton?
我在一个 QToolButton 中添加了 3 个 QAction。
而这个 QToolButton 在一个 QToolBar 中。
像这样:
现在我想通过样式表为每个 QAction 设置图标。
在这种情况下,如何使用 QT 样式表设置图标?
css - QToolButton 文本和图标之间的空间
我有一个 QToolButton。我希望文本和图标出现在上面。我通过 setToolButtonStyle(Qt::ToolButtonTextBesideIcon) 设置按钮样式。
但是图标和文本是如此接近。有没有办法通过css在图标和文本之间留出一些空间?
c++ - QPushButton 和 QToolButton 的区别
我是 Qt 的新手,和之间的区别QPushButton对QToolButton我来说不是很清楚。
我知道 aQToolButton通常用于 aQToolBar并且它通常只显示一个图标,没有文字,但我不太了解两者之间的主要区别。
有没有更大的区别?我应该什么时候使用QPushButton,什么时候应该使用QToolButton?
我想知道这一点以使用最合适的按钮,并且我需要执行一些 GUI 测试,也许它可能是相关的。
qt - 在 Qt 中编写一个充当收银机的 gui 应用程序
请帮我回答以下问题:编写一个充当收银机的 gui。换句话说,客户带来一篮子物品,他们的条形码被扫描,然后计算它们的总数。主窗口应该有一个带有两个菜单的菜单栏:“Sale”和“Item”。销售菜单应具有以下选项:“新建”、“取消”、“完成”和“退出”。项目菜单应具有以下选项:“添加”和“删除”。主窗口还应该有一个工具栏(在窗口底部),其中每个选项都有一个工具栏按钮。
程序启动时,应显示“取消”、“完成”、“添加”和“删除”选项(在菜单和工具栏上)。
我正在使用 Qt。我应该手动编写 gui 代码。我不应该使用 Qt Designer 来创建用户界面。我已经阅读了相关材料,但我只是不知道如何开始解决这个问题。
python - QToolButton 不出现/重叠
我正在将 QToolButtons 动态添加到从 QToolBar 继承的工具栏中。我有一个元组列表(小部件,回调),其中包含应添加到工具栏的内容。理论上,我想按请求对象对它们进行分组,并用 addSeparator() 分隔组。
我的小部件字典由三个小部件元组组成,两个由同一个键拥有。目前,我所有的小部件都是 QToolButtons。
我尝试了以下两个“添加”功能,并附有结果描述:
此设置导致第一个小部件永远不会显示。曾经。我已经打印了他们的地址、父母和相关的密钥,以确认他们是我所期望的:
- 三个独立的小部件
- 与正确的键相关联
- 将我的 QToolBar 类对象作为父小部件
- 并且都按照我期望的顺序进行处理
所有这些条件都是真实的,没有效果。
第二次尝试:
这会导致所有QToolButton 图标重叠,最后一个是模态对话框按钮的全宽。(所有按钮都是使用设置的 QSize (24,24) 创建的。)
此外,与该功能的第一个版本不同,工具栏永远不会正确显示。只是可能(我猜)前四到五个像素显示在我的工具栏上方的小部件和下面的小部件之间。当我将鼠标悬停在它上面时,足以辨认出我三个非常不同的图标的顶部和最后一个的宽度。
我咨询过那些比我自己更了解 Python 的人,没有人有任何想法,即使在程序运行时运行和调试程序之后也是如此。我完全不知所措。
c++ - QToolButton 有多少空间用于文本?
我正在尝试子类QToolButton化以省略其文本。为了告诉文本还有多少空间,我必须取按钮宽度(可用)并从中减去:
图标大小(可用),
带有阴影和其他可爱效果的按钮框架的大小(找不到),
填充(也找不到)。
显然这些东西是依赖于样式的,并且必须有 API 调用来检索它们,但QStyle似乎没有提供任何相关的东西。有什么建议么?


