qtgroupbox

Can you hide a QGroupBox frame but preserve it's content visible?


I have a QGroupBox. Depending on the context, it's title may be redundent (displayed in another place of the GUI), so I then need to make as if the QGroupBox was not here....but I must preserve it's content visible (so I don't want to call QGroupBox::hide())!

I need to do this dynamically at runtime and would like to avoid creating/destroying the QGroupBox + reparenting it's content....there must be an easier way to do this.

What I tried so far:

QGroupBox visible:

enter image description here

I end up with this:

enter image description here

Not too bad...but a line remains....is there a way to completely hide the QGroupBox frame but preserve it's content visible?


Solution

  • You can use QFrame + QGridLayout (or some more complex combination of layouts) + QSS instead of a QGroupBox.

    Considering a QGroupBox only, a trivial solution via QSS could be:

    static const char kSavedTitle[] = "_savedTitle";
    void hideBoxFrame(QGroupBox * box) {
      box->setProperty(kSavedTitle, box->title());
      box->setTitle(QString());
      box->setStyleSheet("border:none");
    }
    void showBoxFrame(QGroupBox * box) {
      box->setTitle(box->property(kSavedTitle).toString());
      box->setStyleSheet(QString());
    }