QSplitter show a divider or a margin between the two widgets

前端 未结 4 1132
情深已故
情深已故 2021-02-14 12:05

I have a QSplitter and two widgets on either side, but I want to be able to have a margin, so that there is a clear transition between the two widgets. I looked in QSplitter and

4条回答
  •  無奈伤痛
    2021-02-14 12:50

    Without going into all the gory details of style sheets I can give you a couple of options:

    1) You can layout a couple of QFrames in your splitter, give them layouts and the put your widgets inside of those frames. You can use the layouts' spacing options (see QLayout::setContentsMargin()) to add some spacing around your widgets.

    2) The style-sheet way (and in my opinion superior way) is to setup some style sheets for your widgets. For a brief example you can do something like this on your widgets that are in your splitter:

    widget->setStyleSheet( "margin-left: 10px" )
    

    If you're doing any kind of GUI design with Qt, I highly recommend you learn all about style sheets, they are your friend. See the Qt style sheets reference for some documentation.

提交回复
热议问题