简体   繁体   中英

How to make Titlebar height fit new Title Font size increase in WxPython?

I've increased the custon AddPrivateFont pointsize to

self.label_font.SetPointSize(27)

of the Title bar of the sample_one.py script from this shared project:

https://wiki.wxpython.org/How%20to%20add%20a%20menu%20bar%20in%20the%20title%20bar%20%28Phoenix%29

From the script of my previous question here:

https://web.archive.org/web/20221202192613/https://paste.c.net.org/HondoPrairie

AddPrivateFont to App Title / Title bar in WxPython?

My problem is I can't figure out how to make the Title bar's height larger so the Title text displays its top part correctly. Currently the top of the Title text is truncated.

I tried adjusting the height and textHeight values from this statement:

        textWidth, textHeight = gcdc.GetTextExtent(self.label)
        tposx, tposy = ((width / 2) - (textWidth / 2), (height / 1) - (textHeight / 1))

from previous ones (in the sample_one.py script):

        textWidth, textHeight = gcdc.GetTextExtent(self.label)
        tposx, tposy = ((width / 2) - (textWidth / 2), (height / 3) - (textHeight / 3))

Because it truncated the bottom (now the bottom shows up correctly but not the top of the Title text).

There is also this method I'm not sure how to handle:

    def DoGetBestSize(self):
        """
        ...
        """

        dc = wx.ClientDC(self)
        dc.SetFont(self.GetFont())

        textWidth, textHeight = dc.GetTextExtent(self.label)
        spacing = 10
        totalWidth = textWidth + (spacing)
        totalHeight = textHeight + (spacing)

        best = wx.Size(totalWidth, totalHeight)
        self.CacheBestSize(best)

        return best

I tried tweaking it and printing results but to no avail.

Here's a preview of the Truncated Title text:

截断的文本标题栏标题 WxPython

What would be the correct approach to finding out what controls the height of the title bar object to fix the truncated title text?

Thanks to @Rolf of Saxony headsup I figured it out!

It took the following 3 steps:

1st Step:

Top Title Text Display from:

class MyTitleBarPnl(wx.Panel):
    def CreateCtrls(self):
        self.titleBar.SetSize((w, 54))

    def OnResize(self, event):
        self.titleBar.SetSize((w, 54))

顶部标题文本显示

2nd Step:

Vertical Spacing Below Title Text Without Text Display:

class MyFrame(wx.Frame):
    def CreateCtrls(self):
        self.titleBarPnl = MyTitleBarPnl(self, -1, (w, 54))

    def OnResize(self, event):
        self.titleBarPnl.SetSize((w, 24))

没有文本显示的标题文本下方的垂直间距

3rd Step:

Vertical Spacing Below Title Text WithText Display:

class MyFrame(wx.Frame):
    def CreateCtrls(self):
        self.titleBarPnl = MyTitleBarPnl(self, -1, (w, 54))

    def OnResize(self, event):
        self.titleBarPnl.SetSize((w, 54))

带有文本显示的标题文本下方的垂直间距

EDIT:

4th Step:

Status Bar Display:

class MyFrame(wx.Frame):
    def CreateCtrls(self):
        self.titleBarPnl = MyTitleBarPnl(self, -1, (w, 54))

    def OnResize(self, event):
        self.titleBarPnl.SetSize((w, 54))
        self.mainPnl.SetSize((w, h - 55))  # 25

状态栏显示

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM