[Qt-interest] setWindowTitle in parent class

Israel Brewster israel at frontierflying.com
Thu Feb 5 01:24:19 CET 2009


On Feb 4, 2009, at 12:41 PM, Robert Hairgrove wrote:

> Israel Brewster wrote:
>> Is there any way to set a window's title in it's parent class and  
>> make
>> it stick? I have a number of forms I have designed using  
>> QtDesigner. In
>> the class declarations for these forms (using the multiple  
>> inheritance
>> approach, although I believe the same would be true of the member
>> approach), all of the classes inherit from the same base class that I
>> wrote, as there are certain functions and behaviors I want all of  
>> forms
>> to share. This works out well-for the most part.
>>
>> One of the behaviors I want all of the classes to share is the window
>> title - this being not a static string, but a file name set at  
>> runtime.
>> However, if I try setting the window title in the constructor of the
>> base class, it is over-ridden by what was set in QtDesigner when I  
>> run
>> setupUI(). I can, of course, set the window title after running  
>> setupUI,
>> but then I have to have the same line of code in each child class,
>> rather than having it once in the base class. Is there anyway to get
>> around this? Thanks.
>> -----------------------------------------------
>> Israel Brewster
>> Computer Support Technician
>> Frontier Flying Service Inc.
>> 5245 Airport Industrial Rd
>> Fairbanks, AK 99709
>> (907) 450-7250 x293
>> -----------------------------------------------
>>
>
> If the window caption is set only at runtime, I don't see any way of
> doing this in QtDesigner. Everything QtDesigner does is already set at
> compile time.
>
> Since all of the inherited windows need to share the same caption,
> though, I would create a protected function in the base class which  
> you
> can call after calling setupUi() from the constructors of the derived
> classes.

That was basically the workaround I was thinking of. Still requires an  
identical line of code in each of the child classes though, so it is  
less than ideal. Just one line though, so it's not too bad :)

>
>
> What happens if you leave the window title blank in QtDesigner? Does  
> it
> still generate any code for setting it to an empty string?

fraid so: xxxx->setWindowTitle(QString());

> If not, you
> might be able to just add the code to the base class' constructor.
> Alternatively, you could manually edit the generated ui_... header  
> file(s).

yeah, that works, with the caveat that they would need to be re-edited  
anytime the UI changes at all :( Thanks for the suggestions!

-----------------------------------------------
Israel Brewster
Computer Support Technician
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list