[Solved] Frame style for a group of buttons?



  • I would like to display a group of radio buttons inside a "sunken" frame. (Yes, I know, modern style is flat. Humor me.) Just a rectangular border in the manner of a QFrame with frame shape StyledPanel and frameShadow "sunken", surrounding my radio set.

    QFrame is not actually a container. I do not want to use a QGroupBox because I do not want a title or space for a title -- in any case, I don't see how to set the frame properties of a group box. Right now I am using an HBoxLayout to contain the buttons but it does not allow for any styling. There is some idea I am not understanding...


  • Moderators

    [quote author="dcortesi" date="1383783235"]
    QFrame is not actually a container. I do not want to use a QGroupBox because I do not want a title or space for a title[/quote]
    i don't know what you don't like about QFrame. QGroupBoix and QFrame are both widgets. QGroupBox just renders differently...
    So QFrame would be fine to use.



  • Hi,
    Think altering the stylesheet of the QFrame will do the trick., but like Raven mentioned, QFrame and QGroupbox are in basic the same with some small rendering differences.



  • Thank you for the input but there is still something I just don't see. Explain like I'm five... I am trying this code (Python):
    @ radio_frame = QFrame()
    radio_frame.setFrameStyle(QFrame.StyledPanel)
    radio_frame.setFrameShadow(QFrame.Sunken)
    radio_frame.setLineWidth(3)
    btn_unicode = QRadioButton('Unicode',radio_frame)
    btn_unicode.setChecked(True) #start with unicode selected
    btn_html = QRadioButton('HTML',radio_frame)@
    This should make the two buttons children of the radio_frame, no? But when I addWidget(radio_frame) to a HBoxLayout, nothing appears. It is as if it had zero width, it just does not appear.

    If instead I do this:
    @ radio_hb = QHBoxLayout()
    btn_unicode = QRadioButton('Unicode',radio_frame)
    btn_unicode.setChecked(True) #start with unicode selected
    btn_html = QRadioButton('HTML',radio_frame)
    radio_hb.addWidget(btn_unicode)
    radio_hb.addWidget(btn_html)
    @
    I can addLayout(radio_hb) and the buttons appear, but of course with no style on their enclosure.


  • Moderators

    setup your QFrame object like you already had. Add the buttons to your layout object. And finally set the layout on your widget. Now your widgets should appear with a border surrounded.

    btw. i don't think explaining programming to a five year old is easier :P



  • OK, thank you! What I was missing was that you can use .setLayout() on any widget including a frame.

    So you make the frame you want, and you put the buttons in a box layout (which makes them exclusive), and you set that layout on the frame, which positions the buttons over the frame shape.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.