English 中文(简体)
我如何利用风格表使在QLabels出现链接习惯?
原标题:How do I customise the appearance of links in QLabels using style sheets?

我有一张<条码>QLabel,上面有一套打着黑暗背景的帽子:

QLabel {
background: black;
color: white;
}

在我添加一个嵌入的URL的文字并设置Qt:TextFormatQt:RichText。 链接显示,沉没的蓝色是黑暗的,难以在黑暗的背景下阅读。

我试图通过诸如:

a { color: white; }
QLabel!visited { color: white; }

但这没有效果。 似乎行之有效的一件事是修改<条码>QPalette:

QPalette newPal(qApp->palette());
newPal.setColor(QPalette::Link, Qt::white);
newPal.setColor(QPalette::LinkVisited, Qt::white);
qApp->setPalette(newPal);

然而,这要求打硬颜色。 难道我能用什么方式把颜色从一个风格上打上?

EDIT:

我先发现另一个问题,即如何定制大字。 如果我只想修改我的植被品种(见上文样本中的<代码>widget/code>>>>。 我不想影响所有其他的<条码>QLabels,因此我如何限制这种植被的棕榈树变化?

最佳回答

答案是没有的。 最近我不得不这样做。

  1. QLabel!visited doesn t work because Qt doesn t track whether QLabel were visited or not.
  2. QLabel { color: ... } doesn t work for links. Can t find why but all I found is a suggestion to use QPallete in this case.
问题回答

One way is to add style="color: whatever" or a class to the inner <span> of the link. I haven t figured out yet how to apply this to the whole application but it s a good start.

我没有明确地确定<条码>QPalette/code>——如果你确定整个申请,它就不起作用,但不是如果你把它放在了子上。 但最后,我需要做的最容易的事情是使用QTextBrowser,而后者则支持subset超文本。 然后,我可以采用普通的CSS风格,推翻链接的颜色:

QTextBrowser browser;
// IMPORTANT! - set the stylesheet before the content
browser->document()->setDefaultStyleSheet("a {color: white; }");
browser->setText(html);

您可将彩色标签定在超文本中。

{ color: inherit; } 




相关问题
Qt: Do events get processed in order?

If I had a class A, where one of its functions does: void A::func() { emit first_signal(); emit second_signal(); } Assuming that a class B has 2 slots, one connected to first_signal, and the ...

How to determine how much free space on a drive in Qt?

I m using Qt and want a platform-independent way of getting the available free disk space. I know in Linux I can use statfs and in Windows I can use GetDiskFreeSpaceEx(). I know boost has a way, ...

Drag & drop with .ui files

I m having big troubles with drag & drop. I ve created a new Qt Designer Form Class in which I have one QListWidget and one QWidget. Now I want to enable dragging & dropping between these two ...

Link errors on Snow Leopard

I creating a small desktop application using Qt and Poco on Mac OS X Snow Leopard. Qt works fine, but once I started linking with Poco I get the following warning: ld: warning: in /Developer/SDKs/...

Showing two windows in Qt4

My friend and I have each created parts of a GUI using Qt 4. They both work independently and I am trying to integrate his form with the my main window. As of now this is the code I am using to try ...

Qt equivalent of .NET data binding?

Is there an equivalent of .NET s data binding in Qt? I want to populate some combo boxes and other widgets with QStrings that refer to specific entities in my database. However, it would be cleaner ...

热门标签