1

Is it possible to make a QToolBar widget background transparent?

Behind it I have a QOpenGLWidget and I'd like to only see the toolbar's icons.

TheLethalCoder
  • 6,668
  • 6
  • 34
  • 69
manatttta
  • 3,054
  • 4
  • 34
  • 72

2 Answers2

1

This works for me with a QGroupBox in front of a QOpenGLWidget:

this->viewButtonBox = new QGroupBox(tr("View"));
QPalette pal;
pal.setColor(QPalette::Background, Qt::transparent);
viewButtonBox->setPalette(pal);

//adding groupbox in front of openglwidget
QVBoxLayout* centralLayout = new QVBoxLayout;
centralLayout->addWidget(viewButtonBox);
this->setLayout(centralLayout);

The QGroupBox is part of the QOpenGLWidgets layout.

Herr von Wurst
  • 2,571
  • 5
  • 32
  • 53
  • Thanks for the answer! Sorry I didn't understand what you meant with "The QGroupBox is part of the QOpenGLWidgets layout." – manatttta Dec 06 '16 at 20:09
  • I added to the code to make it more clear how I set up the layout. – Herr von Wurst Dec 06 '16 at 20:15
  • So you're suggesting I ditch the ToolBar and start using a GroupBox? – manatttta Dec 06 '16 at 20:53
  • No, I am showing you how I set up a transparent QGroupBox in front of a QOpenGLWidget. You're problem is fairly similar, since both QGroupBox and QToolBar inherit their functionality from QWidget. This is supposed to give you a good starting point to implement your transparent QToolBar. – Herr von Wurst Dec 06 '16 at 21:13
0

Isn't it enough to declare QToolBar as child of QOpenGLWidget? Something like:

QMainWindow qW;

QOpenGLWidget *pOG = new QOpenGLWidget;
QToolBar *pTB = new QToolBar(pOG);

qW.setCentralWidget(pOG);

I tested with a QFrame instead of QOpenGLWidget and it works.

BillyJoe
  • 878
  • 7
  • 25