0

I bet my question is obvious from it's title but it may be as well not =)
So let me explain in detail... I have created a QDockWidget and then transformed (I mean promoted to..) it into a subclass using the designer.

So how do I properly access the widgets I've placed? The idea is that all the subclass' objects are dealt within the subclass. The problem (as you may be aware) is that

this->children().count()

Returns this:

QDockWidgetLayout(0x1022373d0) 
QDockWidgetTitleButton(0x102237510, name = "qt_dockwidget_floatbutton") 
QDockWidgetTitleButton(0x102235500, name = "qt_dockwidget_closebutton") 
QWidgetResizeHandler(0x102235de0) 
QAction(0x102221500) 

And none of them contain QLabels and other tish that I want to get my hands on). Looking in ui_mainwindow.h however shed some light on the matter. Widgets are on a dockWidgetContents_3 who is a QWidget that has no parent. So the only way seems to be accessing it through MainWinsow's ui->... And thinking of making ui public makes me a "very sad panda"...

Thanks in advance!

1 Answers1

1

When you say "I have created a QDockWidget and then transformed it into a subclass using the designer", the only thing I can think that this means is that you used the "promote to..." action to turn it into a placeholder for your coded subclass of a QDockWidget. What that means is it expects to place the version from your code in that spot. If your designer has widgets that are laid out within that dock widget, they will not be automatically composed into that class definition. Where they would live is as attributes on the ui object, parallel to that same dock widget.

If you wanted say a QLabel, and a QPushButton, to be composed as part of that custom subclass, then what you need to do is define them in code, and not as part of the visual layout. Then they would be members of that actual subclass.

As of right now, I believe you would find a nested QLabel right on your ui:

ui->dockWidgetContents_3
ui->pushButton_1
ui->label_1

(or however you have chosen to include your ui in your class)

Now lets say you wanted to still be able to visually design the content area of your QDockWidget. What you might do is design that as a separate widget visually. Then promote the dockWidgetContents of the QDockWidget to your custom QWidget. It will then be able to place this composition as a widget with its own children.

ui->CustomDockWidget->widget()->label_1
jdi
  • 90,542
  • 19
  • 167
  • 203
  • It expects to change the values of the added QLabels from within DockWidget (coded subclass to which i've promoted QDockWidget from Designer) – Sergey Tkachenko Aug 16 '12 at 00:01
  • If you have not coded the subclass to have QLabels, then the ones you are laying out in designer are not part of that subclass. They are part of the parent. – jdi Aug 16 '12 at 00:04
  • I mean I do know about where to find them (in MainWindow) but I don't want MainWindow to have tons of code related to DockedWidget and it's functions. – Sergey Tkachenko Aug 16 '12 at 00:05
  • frommyquestion>>>Looking in ui_mainwindow.h however shed some light on the matter. Widgets are on a dockWidgetContents_3 who is a QWidget that has no parent. In other words you tell me to code the labels? – Sergey Tkachenko Aug 16 '12 at 00:05
  • Yes thats exactly what I am saying. What happens is that it is using your custom subclass, but then creating a generic widget to set as its content. And then composing your labels in that. They are not part of your subclass. – jdi Aug 16 '12 at 00:07
  • Ok. But scheme: new QWidget -> new QGridLayout -> setWidget doesnt work either. No errors and no content. I fear I will have to code everything... Sad. – Sergey Tkachenko Aug 16 '12 at 00:10
  • I don't understand. Is your goal to simply encapsulate the various QLabels within your custom dock subclass? – jdi Aug 16 '12 at 00:22
  • yes. DockedWidget operates another class and mainwindow has nothing to do with it bu I thought I could buy some time by creating layout with designer. – Sergey Tkachenko Aug 16 '12 at 00:38
  • Then my answer still stands. If you want to lay it out visually, then design the CustomDockWidget contents as another QWidget in Designer, and promote the CustomDockWidget contents widget to it. Then your CustomDockWidget will have direct access to the members. Or, dont make it another custom widget, and just design it as another QWidget, and then load in that ui to your dockwidget. – jdi Aug 16 '12 at 00:40
  • Thanks! I didn't think about promoting the contents. Worked! It's 5 o'clock here - should get some sleep.) – Sergey Tkachenko Aug 16 '12 at 00:53
  • Woot! Great to hear that it fixed it. G-nite! – jdi Aug 16 '12 at 00:56
  • Indeed. However I'm unable to access widgets on class create, but it is not so bad... – Sergey Tkachenko Aug 16 '12 at 08:53