Hi,
My problem is simple, Move() function doesn't seem to work on a dialog. Did i miss something or is this normal ?
If it is normal is there any way to move a dialog and not to center it as it seems to be by default ?
thanks for your help.
Move a dialog
Re: Move a dialog
Your question is not very clear, but generally: yes, wxWidgets dialogs can be moved, as demonstrated in two different ways by simple code below
But some dialogs (e.g. wxFileDialog) are just displayed as a result of a native API function call and their position cannot be controlled from wxWidgets.
Code: Select all
#include <wx/wx.h>
class MyDlg : public wxDialog
{
public:
MyDlg() : wxDialog(NULL, wxID_ANY, "Test dialog")
{
(new wxButton(this, wxID_ANY, "Move dialog"))->Bind(wxEVT_BUTTON, &MyDlg::OnMoveDialog, this);
}
void OnMoveDialog(wxCommandEvent&)
{
Move(GetPosition().x - 10, GetPosition().y - 10);
}
};
class MyApp : public wxApp
{
public:
bool OnInit()
{
MyDlg dlg;
dlg.Centre();
dlg.Move(dlg.GetPosition().x + 300, dlg.GetPosition().y + 100);
dlg.ShowModal();
return false;
}
}; wxIMPLEMENT_APP(MyApp);
Re: Move a dialog
I will try to be more clear.
I implemented my own dialog directly derived from wxDialog.
By default when i create a dialog the dialog is centered in the app. I would like to change that and be able to put it where i want.
The problem is that the function Move() doesn't seem to work because it does nothing when i try.
I try your code (the second one) and it still doesn't move my dialog.
I implemented my own dialog directly derived from wxDialog.
By default when i create a dialog the dialog is centered in the app. I would like to change that and be able to put it where i want.
The problem is that the function Move() doesn't seem to work because it does nothing when i try.
I try your code (the second one) and it still doesn't move my dialog.
Re: Move a dialog
As usual:
1. List your wxWidgets version and the OS where do you observe the unexpected behaviour and run the code below to see how that behaves.
2. Show your code (as SSCEE).
Also, where do you call your Move() from?
1. List your wxWidgets version and the OS where do you observe the unexpected behaviour and run the code below to see how that behaves.
2. Show your code (as SSCEE).
Also, where do you call your Move() from?
Re: Move a dialog
I use wxWidgets 3.1.0 and i am on Linux (CentOs 7) but the result has to work on windows too.
Here is my code (i cut the non needed part):
The dialog.h
The dialog.cc (only the constructor was neede di think)
And the place where i use the dialog and where i tried your code:
Here the result: the dialog is still centered on the app.
Here is my code (i cut the non needed part):
The dialog.h
Code: Select all
class AddRuleDialog : public wxDialog
{
private:
AliasFilter* alias;
ColorPickerWindow* color;
wxTextCtrl* advControl;
ColorPickerWindow* colorAdv;
wxBoxSizer* mainSizer;
wxBoxSizer* conditionsSizer;
wxBoxSizer* advSizer;
void OnOk(wxCommandEvent& event);
void OnAdvanced(wxCommandEvent& event);
wxDECLARE_EVENT_TABLE();
public:
AddRuleDialog(wxWindow* parent);
~AddRuleDialog();
wxColour GetSelectedColor() const;
utils::string GetConditions() const;
};
Code: Select all
AddRuleDialog::AddRuleDialog(wxWindow* parent) : wxDialog(parent, wxID_ANY, "Add Rule")
{
mainSizer = new wxBoxSizer(wxVERTICAL);
{
conditionsSizer = new wxBoxSizer(wxHORIZONTAL);
alias = new AliasFilter(this, wxID_ANY);
conditionsSizer->Add(alias, 1, wxEXPAND);
color = new ColorPickerWindow(this, wxID_ANY);
conditionsSizer->Add(color);
mainSizer->Add(conditionsSizer, 0, wxEXPAND | wxALL, 5);
}
{
advSizer = new wxBoxSizer(wxHORIZONTAL);
advControl = new wxTextCtrl(this, wxID_ANY, "");
advSizer->Add(advControl);
colorAdv = new ColorPickerWindow(this, wxID_ANY);
advSizer->Add(colorAdv);
mainSizer->Add(advSizer, 0, wxEXPAND | wxALL, 5);
mainSizer->Hide(advSizer);
}
{
wxBoxSizer* buttonsSizer = new wxBoxSizer(wxHORIZONTAL);
wxButton* advButton = new wxButton(this, ID_Advanced, "Advanced");
buttonsSizer->Add(advButton);
// we add this empty window just to fill the span between the 2 couple of buttons.
wxWindow* st = new wxWindow(this, wxID_ANY);
buttonsSizer->Add(st, 1, wxEXPAND);
wxSizer* CancelSizer = wxDialog::CreateButtonSizer(wxCANCEL);
buttonsSizer->Add(CancelSizer);
wxSizer* OkSizer = wxDialog::CreateButtonSizer(wxOK);
buttonsSizer->Add(OkSizer);
mainSizer->Add(buttonsSizer, 1, wxEXPAND);
}
this->SetSizer(mainSizer);
}
Code: Select all
void MyRearrangeList::OnAddButton(wxCommandEvent& event)
{
AddRuleDialog dlg(this);
dlg.Centre();
dlg.Move(dlg.GetPosition().x +300, dlg.GetPosition().y +100);
if (dlg.ShowModal() && dlg.GetReturnCode() == wxID_OK)
{
[...]
}
dlg.Destroy();
}
Re: Move a dialog
There's too much irrelevant code for me to go through it thoroughly.
Assuming MyRearrangeList is a class derived from wxRearrangeList... The only thing I find odd there is that you create a dialog whose parent is not a top level window. Try to change the parent from the rearrange list to the dialog/frame which contains it (or just test with NULL) to see what happens.
BTW, I can test only on MSW and I have never used Linux so I would not know how things work over there regarding moving dialogs...
Assuming MyRearrangeList is a class derived from wxRearrangeList... The only thing I find odd there is that you create a dialog whose parent is not a top level window. Try to change the parent from the rearrange list to the dialog/frame which contains it (or just test with NULL) to see what happens.
BTW, I can test only on MSW and I have never used Linux so I would not know how things work over there regarding moving dialogs...
Re: Move a dialog
Yes in fact i think the only thing interesting is the MyRearrangeList function. The code from the dialog itself is just the elements to build the dialog. I put it in case i did a huge mistake.
Yeah, MyRearrangeList is derived from wxRearrange List. I tried with Null and wxFrame as parent and i still have the same result.
Yeah, MyRearrangeList is derived from wxRearrange List. I tried with Null and wxFrame as parent and i still have the same result.
Re: Move a dialog
Well, I'm out of ideas then. I assume you ran the code from my first post and/or tried to add that dialog to your code and it worked as expected.
Re: Move a dialog
Yep i just tried your 2 solution without link them to my code and it works as expected.
At least i know the problem comes from me and that i can solve it.
At least i know the problem comes from me and that i can solve it.