Align wxFlexGridSizer on the right

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
enricovittorini
Knows some wx things
Knows some wx things
Posts: 34
Joined: Mon Nov 07, 2022 2:54 pm

Align wxFlexGridSizer on the right

Post by enricovittorini »

Hi all,
hopefully someone can help.

I have a panel and a wxFlexGridSizer in it

Code: Select all

wxFlexGridSizer* recapSizer;
recapSizer = new wxFlexGridSizer(2, 3, 0, 5);
recapSizer->SetFlexibleDirection(wxHORIZONTAL);
recapSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED)
;

I would like that the two rows and three columns are aligned on the right in the panel.

is it possible? thanks
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Align wxFlexGridSizer on the right

Post by ONEEYEMAN »

Hi,
You didn't add it to the panel.

]code]
Panel->Add( gridSizer,1. WRIGHT, 0 );
[/Code]

and then call Layout().

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Align wxFlexGridSizer on the right

Post by doublemax »

enricovittorini wrote: Tue Dec 06, 2022 9:15 pm I would like that the two rows and three columns are aligned on the right in the panel.
It's not totally clear what you mean by this. I assume you want the content in all "cells" to be right aligned? If yes, there is no global setting in the sizer for this. It happens when adding each individual item into the grid, with the wxALIGN_RIGHT flag.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Align wxFlexGridSizer on the right

Post by ONEEYEMAN »

doublemax,
My guess would be that the OP has another items on the panel and this sizer should be right aligned.

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Align wxFlexGridSizer on the right

Post by doublemax »

ONEEYEMAN wrote: Wed Dec 07, 2022 6:37 am doublemax,
My guess would be that the OP has another items on the panel and this sizer should be right aligned.
A sizer by itself can't be aligned anywhere. Only its content can. And if the wxFlexGridSizer is inside another sizer, i hope OP will tell us about it.
Use the source, Luke!
enricovittorini
Knows some wx things
Knows some wx things
Posts: 34
Joined: Mon Nov 07, 2022 2:54 pm

Re: Align wxFlexGridSizer on the right

Post by enricovittorini »

thanks I tried but seems not working:

Code: Select all

    MyFrame* frame = new MyFrame();

    wxPanel* m_panel_recap = new wxPanel(frame,wxID_ANY, wxDefaultPosition, wxDefaultSize);
    m_panel_recap->SetBackgroundColour(wxColor(*wxYELLOW));
    

    wxFlexGridSizer* recapSizer = new wxFlexGridSizer(1,3,0,0);
    
    wxStaticText* staticText1 = new wxStaticText(m_panel_recap, wxID_ANY, wxT("Recap Txt1"), wxDefaultPosition, wxDefaultSize);
    recapSizer->Add(staticText1, 1, wxALL, 5);

    wxStaticText* staticText2 = new wxStaticText(m_panel_recap, wxID_ANY, wxT("Recap Txt2"), wxDefaultPosition, wxDefaultSize);
    recapSizer->Add(staticText2, 1, wxALL, 5);

    wxStaticText* staticText3 = new wxStaticText(m_panel_recap, wxID_ANY, wxT("Recap Txt3"), wxDefaultPosition, wxDefaultSize);
    recapSizer->Add(staticText3, 1, wxALL, 5);
    

    recapSizer->Add(m_panel_recap,1, wxRIGHT,0);
    recapSizer->Layout();
    
    frame->Show(true);
    return true;
enricovittorini
Knows some wx things
Knows some wx things
Posts: 34
Joined: Mon Nov 07, 2022 2:54 pm

Re: Align wxFlexGridSizer on the right

Post by enricovittorini »

doublemax wrote: Wed Dec 07, 2022 6:24 am
enricovittorini wrote: Tue Dec 06, 2022 9:15 pm I would like that the two rows and three columns are aligned on the right in the panel.
It's not totally clear what you mean by this. I assume you want the content in all "cells" to be right aligned? If yes, there is no global setting in the sizer for this. It happens when adding each individual item into the grid, with the wxALIGN_RIGHT flag.
I would like the cells of the sxFlexGrid positioned at the right in the pane

Code: Select all

---------------------------------------------------
						cell  cell cell
----------------------------------------------------------
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: Align wxFlexGridSizer on the right

Post by doublemax@work »

Inside a grid-based sizer, you can't have empty space left of a cell. All you can do is to make the first column growable, then it will take up all additional space.

Code: Select all

recapSizer->AddGrowableCol(0, 1);
enricovittorini
Knows some wx things
Knows some wx things
Posts: 34
Joined: Mon Nov 07, 2022 2:54 pm

Re: Align wxFlexGridSizer on the right

Post by enricovittorini »

doublemax@work wrote: Wed Dec 07, 2022 9:55 am Inside a grid-based sizer, you can't have empty space left of a cell. All you can do is to make the first column growable, then it will take up all additional space.

Code: Select all

recapSizer->AddGrowableCol(0, 1);
Thanks tried it. In this way i cannot align "center" the text of the first staticText.

I tried the following and seems fine:
- create a mainSizer of type wxBoxSizer in the Panel
- create a lSizer left sizer of type wxBoxSizer
- add lSizer->AddStretchSpacer(1);
- create a right sizer (recapSizer) of type wxFlexGridSizer

then

Code: Select all

mSizer->Add(lSizer,1,wxEXPAND,0);
mSizer->Add(recapSizer,0,wxTOP | wxRIGHT| wxALIGN_RIGHT,15);
m_panel_recap->SetSizer(mSizer)
;

an this seems working
Post Reply