[Qt-interest] setWindowTitle in parent class
Robert Hairgrove
evorgriahr at hispeed.ch
Wed Feb 4 22:41:47 CET 2009
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.
What happens if you leave the window title blank in QtDesigner? Does it
still generate any code for setting it to an empty string? 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).
More information about the Qt-interest-old
mailing list