Unsolved How to customize layout with CSS
-
Hello,
I'm currently trying to customize the layout and apparently i can't modify anything. I use the setObjectName to define the name of object but don't work out. What is the solution ?
Thanks
-
Hi and welcome to devnet,
What layout ?
What CSS ?
What are you trying to achieve ? -
Thank you.
I added some widgets inside a Layout and i would like to customize the Layout to be able to add border and background but it not working.
# Inside my main self.hLayout = QHBoxLayout() self.hLayout.setObjectName("hLayout") self.hLayout.addWidget(self.btn_menu) # Inside the stylesheet added to my QMainWindow ( self.w ) self.w.setStyleSheet(css.MAIN) MAIN = """ QHBoxLayout#hLayout { background: red; } QPushButton#btn_menu { margin-left: 5px; background: white; }
The CSS doesn't work on the layout selector but working on the QPushButton selector. What is the problem ? Layouts can't be customize ?
-
i would like to customize the Layout
QHBoxLayout#hLayoutYou cannot CSS style layouts, only
QWidget
s, and layouts are not widgets. -
-
@Pl45m4
Yes, but then how does the OP get the layout stuff applied to the widgets which are now inside a singleQFrame
to which the layout applies, instead of to each widget? -
- MainWidget / Window with layout
- Frame
- Layout with stuff
- Frame
Or even multiple QFrames around each button. Instead of adding the widget to the layout directly, add a QFrame and place widget inside frame.
IDK :) This was the first thing that came to my mind
@zonixo
Setting the background color to each widget instead of whole layout wont work for you? - MainWidget / Window with layout
-
@Pl45m4
Ah, OK, so what you really mean is move the original layout (with its widgets) down one level into the newQFrame
. Then he can set the border/background on the frame widget holding the layout instead of on the layout itself. OK. -
This post is deleted! -
-
@Pl45m4 That was a spammer.