vendredi 3 juillet 2015

Docking an existing QWidget in QWindow

For those who are very familiar with C# or VB.NET using the UserControl component in the .NET Framework (which is the hottest framework in my opinion), you were used to adding several buttons that preview different user controls as follows:

1) First you would prepare an appropriate user interface (contains 3 buttons and a single panel on the right area to view each user control after clicking one of the added buttons).

2) Adding 3 user controls from the solution explorer...

3) Inserting the content on each user control...

4) Implementing code for the 3 buttons on the frmMain.cs as the following (for this implementation we will be implementing the "Welcome" button carrying the object name as welcomeBtn, and the rest will have identical code but different user control names instead):

private void welcomeBtn_Click(object sender, EventArgs e)
{
    //Clear up everything from the panel if any item exist(s)...
    mainPanel.Controls.Clear();

    //Create a new instance of a user control for the button...
    UserControl1_Welcome welcome = new UserControl1_Welcome();

    //Show up the created instance of the user control
    mainPanel.Controls.Add(welcome);
}

5) Finally, the program will end up initially like this when running:

http://ift.tt/1HC1jvG

** Usage of the program **

When you click on the "Welcome" button for example, the result should be expected to be like this:

http://ift.tt/1TaGmMr

... and when you click on a different button, lets say "License Agreement" button, you would expect to see something other than your current selection.

MAIN QUESTION How can we bring the simplicity of Windows Forms in QT CREATOR by applying the "QDockWidget"?

I have tried inserting the QDockWidget component with no problems, but when I try to do the equivalent .NET code for adding the QWidget inside the QDockWidget:

ui->dockWidget->setWidget(myWidget);

which I think is equivalent to this line of code in C#.NET (correct me if I'm wrong here):

ui.Controls.Add(myWidget);

After using this code, my program won't crash nor shows anything running...

P.S. I'm sorry for linking the images, I don't have 10 reputation for making them show up...

Aucun commentaire:

Enregistrer un commentaire