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!

2
  • Are you talking about the "promote to..." feature?
    – jdi
    Aug 15, 2012 at 23:44
  • yes jdi. i meant i promoted it. Aug 15, 2012 at 23:48

1 Answer 1

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
12
  • It expects to change the values of the added QLabels from within DockWidget (coded subclass to which i've promoted QDockWidget from Designer) Aug 16, 2012 at 0: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, 2012 at 0: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. Aug 16, 2012 at 0: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? Aug 16, 2012 at 0: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, 2012 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.