[Qt-interest] Change layout in subclass of standard widget ?

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Tue May 26 01:16:31 CEST 2009


Stephen wrote:

I'm trying to derive from a QTableView, to create a custom widget
comprising the table view, and a couple of QPushButtons, like so:

    QVBoxLayout* main_layout = new QVBoxLayout;
    main_layout->addWidget(this);
    main_layout->addLayout(button_layout);

    setLayout(main_layout);
 
However, this doesn't work: the app's main window is never shown, and
the problem seems to be my attempt to add "this" to main_layout.

How does one go about changing the layout of a derived standard
widget in this case ? I'm doing something wrong, but can't see how
to fix it.
 

Hi Stephen, 
 
How can any widget own a layout that contains the widget?  
 
The internal layout of the standard widgets is private to them, so other than the public API, you can only modifiy the original source code to modify the private layout - which is not desirable.  
 
In this case, I suggest a separate widget that contains the table view and buttons, and that connects to the button clicks and does the appropriate actions on the table.  The separate widget can also listen for the view selection signals, and only enable the buttons accordingly. 
 
You can then use the promote feature in designer, or wrap the separate widget in a plugin as a custom widget to be added to designer toolbox.  
 
You may also need to expose the table widget in the separate one, to enable your existing code to continue manipulating the table view. 
 
Regards, 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090526/f494ac1b/attachment.html 


More information about the Qt-interest-old mailing list