简体   繁体   中英

PyQt4 How to draw border around embedded Matplotlib FigureCanvas

I have a pyqt app with an embedded mpl figure like so:

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
...
self.LEEM_fig, (self.LEEM_ax, self.IV_ax) = plt.subplots(1, 2, figsize=(8,8), dpi=100)
self.LEEM_canvas = FigureCanvas(self.LEEM_fig)
...

This mpl canvas sits horizontally aligned with a stack of buttons which are inside a QGroupBox

The GroupBox has a border drawn around it using setStyleSheet:

IVGroup.setStyleSheet("QGroupBox { background-color: \
                            rgb(228, 241, 254); border: \
                            3px solid rgb(58, 83, 155); }")

Here's a link to a picture of how the UI currently looks User Interface

My question is then: how to draw a border around a FigureCanvas? I naively tried to set a styleSheet to self.LEEM_Canvas which is a FigureCanvas but that did not work

self.LEEM_canvas.setStyleSheet("FigureCanvas { background-color: \
                            rgb(228, 241, 254); border: \
                            3px solid rgb(58, 83, 155); }")

The only thing I could think of to try next would be to embed a separate QFrame (generic QWidgets don't support borders according to the Qt stylesheet reference) inside the current tab and place this frame horizontally alligned with the QGroupBox - then embed the mpl FigureCanvas into the QFrame - then draw a border around the QFrame - but that seems like a really roundabout way

我发现的唯一解决方法是将FigureCanvas放置在QHboxLayout或QVBoxLayout中,然后将该布局添加到QGroupBox中,然后使用QSS样式字符串(如“”“ QGroupBox {background-color:rgb(48 ,47,47); border:8px solid rgb(108,122,137); border-radius:6px}“”“

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM