ColinKennedy
ColinKennedy

Reputation: 998

PyQt - Draw rectangle behind a widget

I have a QStackedWidget with a QLineEdit and a couple other widgets inside of it. This QStackedWidget is fairly dynamic - you can move it within its layout by clicking/dragging, change its current widget by right clicking it, etc.

I'd like to draw a simple, gray rectangle or a gray rounded rectangle around the QStackedWidget to let people know that the QLineEdit they're looking at is important. This drawn rectangle has to be able to follow the QStackedWidget so that it follows properly with the widget when I move it to other locations on-screen.

I've tried several approaches so far but they've all fallen short in some regard or another or it just wouldn't move with the widget. Can anyone show me how?

Upvotes: 0

Views: 1157

Answers (1)

Brendan Abel
Brendan Abel

Reputation: 37549

Depending on how your clicking/dragging is implemented, you should just be able to place the QStackedWidget inside another QFrame, or put a QFrame inside your QStackedWidget and put all the other controls inside the QFrame. QFrame's support drawing borders around them.

frame = QFrame()
frame.setFrameStyle(QFrame.StyledPanel)
frame.setLineWidth(2)

Upvotes: 1

Related Questions