2017-01-16 1 views
0

Mon programme wxWidgets construit avec gcc et wxSmith a plusieurs calibreurs avec des textes et des boutons, une fenêtre wxMathPlot et un wxGrid. Lorsque j'ai choisi quelque chose dans un choix, la grille remplit avec une quantité différente d'informations et développe plus de lignes si nécessaire ou supprime les lignes inutiles. Comme je commence avec 1 ligne, quand le choix est fait, il y a toujours une ligne affichée, mais dès que je touche la bordure de la fenêtre pour la redimensionner, tout est redimensionné. La grille se développe de sorte que chaque ligne est affichée sans barre de défilement et que la fenêtre de tracé croît ou se rétrécit en fonction de l'espace laissé par la grille. Est-il possible de coder ce comportement, de sorte qu'il est appelé à chaque fois que la grille reçoit une nouvelle entrée? J'ai essayé avecRedimensionnement automatique de wxGrid

UserGrid->Fit(); 
SendSizeEvent(); 

à la fin de la méthode de la grille, mais cela ne fonctionne pas. J'ai une méthode OnResize() comme suit:

void Lizenz_Logfile_ReaderFrame::OnResize(wxSizeEvent& event) 
{ 
    DoGetBestSize(); 
    UserGrid->Fit(); 
    //UserGrid->Refresh(); 
    Layout(); 

} 

Ceci est ma mise en page (dans le cas où certains des paramètres que j'essayées crée le comportement désiré)

//(*Initialize(Lizenz_Logfile_ReaderFrame) 
    wxBoxSizer* BoxSizer4; 
    wxMenuItem* MenuItem2; 
    wxFlexGridSizer* FlexGridSizer3; 
    wxMenuItem* MenuItem1; 
    wxFlexGridSizer* FlexGridSizer5; 
    wxBoxSizer* BoxSizer2; 
    wxMenu* Menu1; 
    wxBoxSizer* BoxSizer1; 
    wxMenuBar* MenuBar1; 
    wxFlexGridSizer* FlexGridSizer6; 
    wxMenu* Menu2; 

    Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE|wxFULL_REPAINT_ON_RESIZE, _T("wxID_ANY")); 
    SetClientSize(wxSize(525,713)); 
    Panel4 = new wxPanel(this, ID_PANEL4, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL4")); 
    BoxSizer1 = new wxBoxSizer(wxVERTICAL); 
    BoxSizer2 = new wxBoxSizer(wxHORIZONTAL); 
    LogFilePickerCtrl = new wxFilePickerCtrl(Panel4, ID_FILEPICKERCTRL2, wxEmptyString, wxEmptyString, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxFLP_FILE_MUST_EXIST|wxFLP_OPEN|wxFLP_USE_TEXTCTRL, wxDefaultValidator, _T("ID_FILEPICKERCTRL2")); 
    BoxSizer2->Add(LogFilePickerCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    BoxSizer1->Add(BoxSizer2, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    FlexGridSizer5 = new wxFlexGridSizer(0, 3, 0, 0); 
    RadioButtonProe = new wxRadioButton(Panel4, ID_RADIOBUTTON4, _("PROE"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP, wxDefaultValidator, _T("ID_RADIOBUTTON4")); 
    FlexGridSizer5->Add(RadioButtonProe, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    RadioButtonEng = new wxRadioButton(Panel4, ID_RADIOBUTTON5, _("ENG"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_RADIOBUTTON5")); 
    FlexGridSizer5->Add(RadioButtonEng, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    RadioButtonUi = new wxRadioButton(Panel4, ID_RADIOBUTTON6, _("UI"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_RADIOBUTTON6")); 
    FlexGridSizer5->Add(RadioButtonUi, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    StaticText7 = new wxStaticText(Panel4, ID_STATICTEXT1, _("Label"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1")); 
    FlexGridSizer5->Add(StaticText7, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    ChoiceDate = new wxChoice(Panel4, ID_CHOICE3, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE3")); 
    FlexGridSizer5->Add(ChoiceDate, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    BoxSizer1->Add(FlexGridSizer5, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    FlexGridSizer6 = new wxFlexGridSizer(0, 3, 0, 0); 
    StaticText10 = new wxStaticText(Panel4, ID_STATICTEXT20, _("Durchschnittlich genutzte Lizenzen \nam Tag"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT20")); 
    FlexGridSizer6->Add(StaticText10, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    StaticTextDurchschnitt = new wxStaticText(Panel4, ID_STATICTEXT21, _("Anzahl"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT21")); 
    FlexGridSizer6->Add(StaticTextDurchschnitt, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    FlexGridSizer6->Add(-1,-1,1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    StaticText12 = new wxStaticText(Panel4, ID_STATICTEXT22, _("Maximum genutzte Lizenzen"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT22")); 
    FlexGridSizer6->Add(StaticText12, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    StaticTextMaximum = new wxStaticText(Panel4, ID_STATICTEXT23, _("Anzahl"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT23")); 
    FlexGridSizer6->Add(StaticTextMaximum, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    StaticTextMaximumTime = new wxStaticText(Panel4, ID_STATICTEXT24, _("Wann"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT24")); 
    FlexGridSizer6->Add(StaticTextMaximumTime, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    StaticText15 = new wxStaticText(Panel4, ID_STATICTEXT25, _("Minimum genutzte Lizenzen"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT25")); 
    FlexGridSizer6->Add(StaticText15, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    StaticTextMinimum = new wxStaticText(Panel4, ID_STATICTEXT26, _("Anzahl"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT26")); 
    FlexGridSizer6->Add(StaticTextMinimum, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    StaticTextMinimumTime = new wxStaticText(Panel4, ID_STATICTEXT27, _("Wann"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT27")); 
    FlexGridSizer6->Add(StaticTextMinimumTime, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    BoxSizer1->Add(FlexGridSizer6, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    BoxSizer4 = new wxBoxSizer(wxHORIZONTAL); 
    MathPlot1 = new mpWindow(Panel4, ID_MATHPLOT2, wxDefaultPosition, wxDefaultSize, wxRAISED_BORDER|wxTAB_TRAVERSAL); 
    xAxis = new mpScaleX(_("Time"), 1, true); 
    MathPlot1->AddLayer(xAxis); 
    yAxis = new mpScaleY(_("Licenses"), 4, true); 
    MathPlot1->AddLayer(yAxis); 
    VectorLicenses = new mpFXYVector(_("Licenses"), 0); 
    VectorLicenses->SetContinuity(true); 
    MathPlot1->AddLayer(VectorLicenses); 
    VectorUser = new mpFXYVector(_("User"), 0); 
    VectorUser->SetContinuity(true); 
    MathPlot1->AddLayer(VectorUser); 
    MathPlot1->UpdateAll(); 
    MathPlot1->Fit(); 
    BoxSizer4->Add(MathPlot1, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    BoxSizer1->Add(BoxSizer4, 2, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    FlexGridSizer3 = new wxFlexGridSizer(0, 3, 0, 0); 
    StaticText9 = new wxStaticText(Panel4, ID_STATICTEXT12, _("User\nFür Statistik Lizenz oben wählen"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT12")); 
    FlexGridSizer3->Add(StaticText9, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    ChoiceUser = new wxChoice(Panel4, ID_CHOICE2, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_CHOICE2")); 
    FlexGridSizer3->Add(ChoiceUser, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    FlexGridSizer3->Add(-1,-1,1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    StaticText4 = new wxStaticText(Panel4, ID_STATICTEXT13, _("Durchschnittliche Zeit \nLizenznutzung pro Tag"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT13")); 
    FlexGridSizer3->Add(StaticText4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    StaticTextStundenDurchschnitt = new wxStaticText(Panel4, ID_STATICTEXT14, _("Betrag"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT14")); 
    FlexGridSizer3->Add(StaticTextStundenDurchschnitt, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    StaticText1 = new wxStaticText(Panel4, ID_STATICTEXT15, _("Stunden"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT15")); 
    FlexGridSizer3->Add(StaticText1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    StaticText8 = new wxStaticText(Panel4, ID_STATICTEXT16, _("Tag mit Stundenmaximum"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT16")); 
    FlexGridSizer3->Add(StaticText8, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    StaticTextStundenMax = new wxStaticText(Panel4, ID_STATICTEXT17, _("Stunden"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT17")); 
    FlexGridSizer3->Add(StaticTextStundenMax, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    StaticTextTagMax = new wxStaticText(Panel4, ID_STATICTEXT18, _("Tag"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT18")); 
    FlexGridSizer3->Add(StaticTextTagMax, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    BoxSizer1->Add(FlexGridSizer3, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); 
    UserGrid = new wxGrid(Panel4, ID_GRID1, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE, _T("ID_GRID1")); 
    UserGrid->CreateGrid(1,5); 
    UserGrid->EnableEditing(false); 
    UserGrid->EnableGridLines(true); 
    UserGrid->SetColLabelValue(0, _("Lizenz")); 
    UserGrid->SetColLabelValue(1, _("Tag")); 
    UserGrid->SetColLabelValue(2, _("Von")); 
    UserGrid->SetColLabelValue(3, _("Bis")); 
    UserGrid->SetColLabelValue(4, _("Nutzungszeit")); 
    UserGrid->SetDefaultCellFont(UserGrid->GetFont()); 
    UserGrid->SetDefaultCellTextColour(UserGrid->GetForegroundColour()); 
    BoxSizer1->Add(UserGrid, 0, wxEXPAND|wxALIGN_LEFT|wxALIGN_TOP, 0); 
    Panel4->SetSizer(BoxSizer1); 
    BoxSizer1->Fit(Panel4); 
    BoxSizer1->SetSizeHints(Panel4); 
    MenuBar1 = new wxMenuBar(); 
    Menu1 = new wxMenu(); 
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL); 
    Menu1->Append(MenuItem1); 
    MenuBar1->Append(Menu1, _("&File")); 
    Menu2 = new wxMenu(); 
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL); 
    Menu2->Append(MenuItem2); 
    MenuBar1->Append(Menu2, _("Help")); 
    SetMenuBar(MenuBar1); 
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1")); 
    int __wxStatusBarWidths_1[1] = { -1 }; 
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL }; 
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1); 
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1); 
    SetStatusBar(StatusBar1); 

    Connect(ID_FILEPICKERCTRL2,wxEVT_COMMAND_FILEPICKER_CHANGED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnLogFilePickerCtrlFileChanged1); 
    Connect(ID_RADIOBUTTON4,wxEVT_COMMAND_RADIOBUTTON_SELECTED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnRadioButtonProeSelect); 
    Connect(ID_RADIOBUTTON5,wxEVT_COMMAND_RADIOBUTTON_SELECTED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnRadioButtonEngSelect); 
    Connect(ID_RADIOBUTTON6,wxEVT_COMMAND_RADIOBUTTON_SELECTED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnRadioButtonUiSelect); 
    Connect(ID_CHOICE3,wxEVT_COMMAND_CHOICE_SELECTED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnChoiceDateSelect); 
    Connect(ID_CHOICE2,wxEVT_COMMAND_CHOICE_SELECTED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnChoiceUserSelect); 
    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnQuit); 
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Lizenz_Logfile_ReaderFrame::OnAbout); 
    //*) 

Y at-il un moyen d'obtenir la fenêtre redimensionner afin que la grille soit entièrement affichée?


Edit: Comme je l'ai découvert pendant le débogage, OnResize() ne sera jamais appelé lors du redimensionnement de la fenêtre effectivement. Cela doit être fait en arrière-plan, car je ne fais rien d'autre avec la taille de ma fenêtre.


Edit 2: Après avoir essayé un peu, il semble que après avoir utilisé UserGrid->AppendRow() la grille ne pas repeindre bien. Après cette ligne, une barre de défilement visible à l'avance disparaît et ne réapparaît que si la fenêtre est redimensionnée par l'utilisateur. J'ai déjà essayé UserGrid->AdjustScrollbars() suivi de UserGrid->ForceRefresh() sans effet.

+0

Que diriez-vous d'utiliser wxPanel? Vous donne la possibilité de les afficher ou de les masquer et tout ce que vous devez appeler est les fonctions «Layout» et «Fit» de la fenêtre principale. – macroland

+0

J'ai essayé Layout and Fit à plusieurs endroits mais cela n'a pas eu le résultat attendu. – Lehue

Répondre

1

De http://docs.wxwidgets.org/trunk/overview_windowsizing.html, wxWidgets fournit deux méthodes principales pour le dimensionnement:

  • wxWindow :: Fit() définit la taille d'une fenêtre pour adapter à ses enfants. La taille de chaque enfant est ajoutée et cette fenêtre parent change sa taille pour les adapter tous.
  • wxWindow :: Layout() le contraire. Les enfants vont changer leur taille, selon les règles de sizer, de sorte qu'ils peuvent tenir dans l'espace disponible de leur parent. [...] est ce qui est appelé par le gestionnaire par défaut EVT_SIZE pour les fenêtres de conteneur

Parce qu'une grille peut avoir des milliers de lignes/cols sa taille peut être énorme. N'essayez pas de dire au parent de l'adapter. Il vaut mieux définir les tailles max et min pour la grille (ou son calibreur) et ensuite utiliser Fit() ou Layout() chaque fois que vous changez le nombre de lignes/cols ou leurs tailles.

+0

wxWindow :: Fit() et wxWindow :: Layout() ne semblent pas avoir d'effet ici. Je peux ajouter une taille maximum pour le wxGrid, mais quand il y a trop de lignes pour tenir dans la taille maximale, je ne suis pas capable de générer une barre de défilement sans redimensionner manuellement toute la fenêtre par souris.J'ai essayé 'wxGrid :: AdjustScrollbars()' et 'wxGrid :: ForceRefresh()' suivi de 'Fit()' ou 'Layout()' – Lehue