3

I know that for a QObject, there is a way to find all QObjects that are considered children - but I don't know if that means I would be able to find all widgets in the MainWindow. Plus, I don't want to find any non-widgets.

I ask because I'm trying to style a window translucent, and the background color is obviously not being applied to all widgets. Yet, I'm applying it to every widget I can think of. I don't want to change global opacity - text should remain opaque.

The pic below has the code for setting the translucency, as well as a picture of the window itself. As you can see, the text-edit area is colored. But I'm setting that, too (it's 'Ed'), so I don't know why it is!

Pic of the code and the window.

SaburoutaMishima
  • 269
  • 4
  • 15

1 Answers1

7

You can use QObject::findChildren<QWidget*>() to find all children widgets.

Lahiru Chandima
  • 22,324
  • 22
  • 103
  • 179
  • You've correctly answered my question. Unfortunately, I still can't get the result I'm shooting for. I'm iterating over findChildren from the MainWindow, and then from each child Object I find. I give them all a palette with Base AND foreground set to transparent. And still, the QTextEdit in the 1st tab, has an opaque background. – SaburoutaMishima Aug 30 '15 at 16:44
  • 1
    @SaburoutaMishima I'm late to the party but you really should use QSS (Qt version of CSS). It allows you to mass set styles for application, including complex things like buttons, scrollbars or combo boxes. – Tomáš Zato Aug 03 '16 at 22:02
  • @Zato I appreciate the response. I was able to solve this. I also don't consider CSS in any way a substitute for being able to programatically access sub-objects. Thankfully, I didn't need it. – SaburoutaMishima Aug 25 '16 at 02:58
  • For the sake of completeness and because I ended up here from google, note that if you have a certain subclass of QWidget that you're looking for, pass it to the template class of findChildren. – Phlucious Apr 15 '18 at 06:57