Welcome! Log In Create A New Profile


Different forms in QMainWindow

Posted by sharkie 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Different forms in QMainWindow
April 18, 2007 10:52PM

Can someone please help me with a high level explanation of how to trigger multiple forms when centralWidget is used.

I struggle to figure out how to replace one layout with another once centralWidget is set.

My attempt looks something like this: I have a class loginMainWindow, and in the constructor's implementation calls to the functions for creating menus, toolbars, and actions. I also call a function that creates my widget that includes my layout and I set this widget as my centalWidget in this function. Up to this point everything seems to be working.

The problem I'm having is to have an action trigger a different layout/view/form. I created a similar member function as the one for my initial log on page but have no idea what to do with the central widget.

Would appreciate any guidance or other QMainWindow extended applications which have different forms depedent on action listeners.

Thanking you in advance
Re: Different forms in QMainWindow
April 19, 2007 04:59PM
Hey sharkie,

I'm not sure if I understood you correctly, but if you are asking how to popup a new form over the main form then it's simple:

create a new class derived from QDialog:

class UserDetailsDialog : public QDialog {...};

in the slot that you use to handle all the QActions do this:

UserDetailsDialog myDialog(this, ""winking smiley;

You don't actually replace anything on the main form - that always stays the same.


Re: Different forms in QMainWindow
April 19, 2007 05:16PM
Hi Mark,

Thanks, this helps me a lot. For some reason I thought we were not allowed to use dialogs for this exercise.

I tried to changed the layout assigned to the centralWidget every time an action is called.

Just one more question, when you say:
"You don't actually replace anything on the main form - that always stays the same."
does that mean that one and only one layout can be assigned to a centralWidget.
If you create parent-child relationships, how do you manange these layouts specifically in a mainwindow...or dont you

Thanks again,
Re: Different forms in QMainWindow
April 19, 2007 06:34PM

Well firstly - I just assumed that we were meant to use a popup dialog - the question is not very clear about that. It just makes sense to do it that way to me.

I hope thats right though cos I just submitted my assignment haha!.

As for the second question - you can have multiple layouts in the central widget, but they will all show at the same time. The way I understood what you were trying to do, is that you were creating two centralWidgets and just swapping between the two to change the appearance of the main window. I quess this could work (i've never done this so I couldn't say - but it seems to not be unreasonable). I just meant that from my experience you wouldn't want to do this in reality. Imagine if you need to reuse the screen that is on centralWidget number 2 in another application, it would be better to create that screen as a separate class derived from QWidget or some other base class, rather that builtin to a funtion in your MainWindow application.

so it's not that it can't be done - just that it wouldn't make sense to do it in a
real development project.

I hope I understood what u were asking properly though - otherwise just ignore whatever i just said hahaha!!

later man.
Re: Different forms in QMainWindow
April 19, 2007 08:38PM
Thanks for the explanation. Makes sense now.
Sorry, only registered users may post in this forum.

Click here to login