Results 1 to 4 of 4

Thread: Promoting a QDockWidget to a custom subclass in Designer

  1. #1
    Join Date
    Oct 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Promoting a QDockWidget to a custom subclass in Designer

    I made a custom QDockWidget subclass to handle some specific I/O tasks, but I am having some trouble placing it into a Qt Designer form (a QMainWindow based form).

    Qt versions: 4.5.1 on Gentoo Linux, 4.5.2 on Mac OS X

    Promoting the QDockWidget doesn't cause any complaints, but when I run my program, the widgets inside my custom dock widget do not appear. The generated code shows Qt is trying to set the contents of my widget to an empty QWidget (dockWidgetContents). Designer does not seem to let me get rid of this dockWidgetContents QWidget, but I can modify its properties. The attached example is for this scenario.

    I tried making a plugin for Designer, but that seems like a lot of work just to place it in a form with Designer. Also, I seem to have failed some form of container widget aspect of creating plugins (domXml stuff that I'm supposed to put in).

    Promoting the QWidget (dockWidgetContents) inside a generic QDockWidget on the main form has layout issues. The generated code seems to want to replace the layout that the QWidget version of my custom subclass already has. The runtime error is: QLayout: Attempting to add QLayout "" to CustomSubclass "ObjectName", which already has a layout


    Any thoughts on how best to solve this issue? It seems strange that Qt Designer lets you put together custom QDockWidget based forms, but fails at letting QDockWidgets be promoted. I can live with the custom code solution, but it seems like the Designer should have a decent way to handle this.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Promoting a QDockWidget to a custom subclass in Designer

    Why exactly do you subclass QDockWidget? Shouldn't you be subclassing the class you put inside the dock widget instead?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Promoting a QDockWidget to a custom subclass in Designer

    That actually makes more sense than what I was doing. One reason I did not do that is when I attempted something similar I apparently did not change my subclass to inherit off of QWidget instead of QDockWidget (tried QDockWidget way first), which gave some strange dock widget inside a dock widget results.

    I was also considering adding functionality to the dock widgets, since I plan to use them extensively. Although I suppose if I wanted to add functionality to the QDockWidgets, I should keep the QDockWidget functionality in a special subclass instead of involving functionality unrelated to the docking features. Sleep deprivation must be getting to me...

  4. #4
    Join Date
    Dec 2009
    Posts
    1
    Thanks
    1

    Default Re: Promoting a QDockWidget to a custom subclass in Designer

    I think I understand what you were trying to do and know one reason you might want to do that is the ease of creating a dock widget in the designer (outside of the mainframe form) that you can reuse. Yeah, there are other ways of doing it, but that is the most intuitive (for me anyway).

    In order to do what you are trying to do, call your QDockWidget sub-class setupUI (assuming you did the multiple-inheritance way of subclassing using designer forms) after the mainframe has done all its setupUi stuff, not in your sub-class's constructor.

    That should do what you want.

Similar Threads

  1. Replies: 15
    Last Post: 25th March 2007, 03:40
  2. Custom Style and Qt Designer 3
    By iukpo in forum Qt Tools
    Replies: 1
    Last Post: 23rd January 2007, 00:39
  3. Global includes with designer custom widgets
    By mab in forum Qt Programming
    Replies: 2
    Last Post: 5th October 2006, 22:06
  4. Promoting a custom widget derived from QWidget Qt4
    By high_flyer in forum Qt Tools
    Replies: 1
    Last Post: 2nd March 2006, 18:50
  5. Replies: 4
    Last Post: 1st March 2006, 23:11

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.