【问题标题】:How to exclude a specific qwidget ( QToolTip ) from the stylesheet applied on the parent如何从应用于父级的样式表中排除特定的 qwidget ( QToolTip )
【发布时间】:2016-02-17 04:15:48
【问题描述】:

我有从 QWidget 派生的 Widget 类。之前有一个样式表应用在它上面,用于设置小部件中所有字符串的字体大小

setStyleSheet( QString( "font-size: %1px;" ).arg( fontSize ) );

这导致小部件中的所有字符串都具有特定的字体大小。 但我希望小部件中的工具提示具有默认字体样式。

有没有办法做到这一点?

我在“qtcentre”中发现了一个类似的问题:http://www.qtcentre.org/threads/12828-Setting-stylesheet-for-quot-almost-quot-all-widgets

【问题讨论】:

  • 在全局样式表中,有没有办法将与工具提示相关的内容分开?
  • 我不知道,但我认为,正如这个链接中提到的,stackoverflow.com/questions/31979224/…,带有 QToolTip{ "/*style;*/" } 的样式表应该可以做到。
  • 好。因此,在全局样式表已经设置之后,您可以再次使用 QToolTip{font-size: 10} 左右设置全局样式表。只要范围是有限的,其余的将保持不变。
  • @AlexanderVX 感谢您的回复。我尝试了以下方法: QString styleshee( "font-size: %1px; QToolTip{ font-size: %2pt; }" ).arg( fontSize ).arg ( toolTipFontSize );..... where fontSize = 100 & toolTipFontSize = 11 ..... 但是所有的文字仍然是 font-size = 100;

标签: c++ qt stylesheet qwidget


【解决方案1】:

您可以使用* 选择器将第一个字体大小设置为所有小部件,然后使用类型选择器将第二个字体大小设置为QToolTip 对象:

setStyleSheet("*{font-size: 20px;} QToolTip{ font-size: 8pt; }");

【讨论】:

  • 对我不起作用:setStyleSheet("*{background-color: rgb(238, 209, 150); border: 0;} QToolTip{}")
  • UPD:由setStyleSheet("*{background-color: rgb(238, 209, 150); border: 0;} QToolTip{background: palette(base)}") 设法做到这一点。不过,不是确切的工具提示调色板。
猜你喜欢
  • 1970-01-01
  • 2018-01-08
  • 2015-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-17
  • 1970-01-01
  • 2012-01-29
相关资源
最近更新 更多