开发者

pyqt - how to remove the boder from a widget in the statusbar?

I am using QLabel widgets to display error messages to the user in the status bar. This is working fine with the following code;

self.statusbar = self.statusBar()

label = QtGui.QLabel("this is a test error message")
stylesheet = """
QLabel {
font-weight: bold;
color: #FF0000;
}
"""
label.setStyleSheet(stylesheet)
self.statusbar.ad开发者_开发知识库dWidget(label)

The only problem is that the widgets have a border around them that I can not get rid of. This is not functionally a problem as the message is still visible but it does look rather ugly and I'd like to get rid of it. I can not work out where it is coming from. Whether it is something I need to set on the statusbar or the widget. I have tried modifying the stylesheet for both the statusbar and label to add "border: 0px" to no avail. I have tried setting the labels frame to label.setFrameShape(QtGui.QFrame.NoFrame) but that doesnt seem to be it either.

Anyone have any ideas how I can get rid of it?


You do this with Style sheets. You probably have a line like this Application app(argc, argv);

underneath that, add one like this: app.setStyleSheet("QStatusBar::item { border: 0px solid black }; ");

and those pesky boxes will be gone.


try using self.statusbar.showMessage('this is a test error message'), as the QStatusBar is not designed for showing labels. If you need more frexibility than this you may consider subclassing QStatusBar and changing its paintEvent function to special-case labels. Either of these approaches will be much easier to maintain than setting stylesheets for each label you want to but on there anyway, but as usual, YMMV.

for more info check out the manual page for QStatusBar

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜