This code:
import wx class MainFrame(wx.Frame): def __init__(self): super().__init__(None, title="wxchoice size test") box = wx.BoxSizer(wx.VERTICAL) self.SetSizer(box) choice1 = wx.Choice(self) choice1.Set(["Item one", "Item two"]) box.Add(choice1) choice2 = wx.Choice(self, -1, wx.DefaultPosition, wx.DefaultSize, ["Item one", "Item two"]) box.Add(choice2) app = wx.App() frame = MainFrame() frame.Show() app.MainLoop()
Produces this window:
If I then select (as the user) an item in each dropdown, it's clear that the first one is too short to contain a line of text:
If I extend the constructor as follows to select an item before layout happens automatically, the problem is resolved:
def __init__(self): # ... same as before ... choice1.SetSelection(0) choice2.SetSelection(0)
However if I invoke layout manually first, the problem is not resolved:
def __init__(self): # ... same as before ... self.Layout() choice1.SetSelection(0) choice2.SetSelection(0) # calling it a second time doesn't make any difference #self.Layout()
I'm guessing empty text is being measured as very short?
A similar thing happens with wxTextCtrl (the vertical padding is almost nonexistent), but curiously that happens even when it's constructed with non-empty text, and it only reproduces with C++ — it's fine via wxPython.
I know this used to work, but can't be much more specific than that, unfortunately.
Arch Linux x64
wxGTK 3.2.2
GTK 3.24.36
Using theme breeze-gtk 5.26.5 on X11
diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp index 470e765423..ed488971d4 100644 --- a/samples/minimal/minimal.cpp +++ b/samples/minimal/minimal.cpp @@ -144,6 +144,9 @@ MyFrame::MyFrame(const wxString& title) // set the frame icon SetIcon(wxICON(sample)); + auto main_sizer = new wxBoxSizer(wxVERTICAL); + SetSizer(main_sizer); + #if wxUSE_MENUBAR // create a menu bar wxMenu *fileMenu = new wxMenu; @@ -167,7 +170,7 @@ MyFrame::MyFrame(const wxString& title) wxButton* aboutBtn = new wxButton(this, wxID_ANY, "About..."); aboutBtn->Bind(wxEVT_BUTTON, &MyFrame::OnAbout, this); sizer->Add(aboutBtn, wxSizerFlags().Center()); - SetSizer(sizer); + main_sizer->Add(sizer); #endif // wxUSE_MENUBAR/!wxUSE_MENUBAR #if wxUSE_STATUSBAR @@ -175,6 +178,21 @@ MyFrame::MyFrame(const wxString& title) CreateStatusBar(2); SetStatusText("Welcome to wxWidgets!"); #endif // wxUSE_STATUSBAR + + const wxString choice_labels[] = {"Item one", "Item two"}; + auto choice1 = new wxChoice(this, wxID_ANY); + choice1->Set(2, choice_labels); + main_sizer->Add(choice1); + auto choice2 = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 2, choice_labels); + main_sizer->Add(choice2); + + // wxTextCtrl is similarly very cramped vertically... though not under wxPython for some reason + main_sizer->Add(new wxTextCtrl(this, wxID_ANY, "hello world")); + + Layout(); + // These fix it, unless you also uncomment Layout() + //choice1->SetSelection(0); + //choice2->SetSelection(0); }
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
I believe GTK will only size the combobox based on the currently selected string, so there is an existing workaround in the wxChoice code that does this manually for the width of the box (wxChoice::DoGetBestSize()
calls wxChoiceBase::DoGetBestSize()
, which iterates through every single item in the box to find its width. That function discards the height, so I guess we should instead try to find the height as well in that function.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
The minimal
sample with your changes looks fine for me. Might be a problem with your theme.
That function discards the height
We get the height from GTK, in wxChoice::DoGetSizeFromTextSize()
.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
That's strange; this theme is a first-class KDE project, and this regressed somewhere, but the theme seems to be largely stable.
I don't see this happening anywhere in gimp, firefox, thunderbird, etc. either — for comparison, left is slade (wx), right is gimp (gtk)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
I have definitely seen weird sizing behavior with GTK comboboxes in the past. The specific case I had was a bitmap combobox (so wxBitmapComboBox
, which is a GTK combobox at its core) was not getting sized appropriately when there was no selection. The way to fix it was select an item, compute the minimum size, apply that size, then deselect the item (e.g. this code: https://gitlab.com/kicad/code/kicad/-/commit/1931677316c35124434dfbd62a98e33cb99581d2). I wouldn't be surprised if there is something in the GTK cell that is being used to get the height of the combobox that doesn't like the empty text.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
I can confirm that this issue is theme specific.
It can also be seen in the unmodified widgets sample on the 'Choice' page, where the wxChoice
is initially empty.
On openSUSE Leap 15.5 with the default theme Breeze the wxChoice
is displayed truncated.
But with the theme Adwaita it looks correct.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
Thanks, I can reproduce with the Breeze
theme.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
Thanks for the quick fix, works well.
Please also backport this improvement to 3.2. TIA!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
Closed #23382 as completed.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
Paul, could you please update docs/changes.txt
in 3.2 too? TIA!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.