![]() ![]() |
Dec 8 2003, 06:12 AM
Post
#1
|
|
|
Group: Members Posts: 8 Joined: 8-December 03 Member No.: 1,066 |
I'm trying to move into c++ for the Zaurus and am at the baby step stages.
I've had some luck with apps that have only one screen and am now trying to develop one that displays two. With the code below, I can display either ScreenOne or ScreenTwo by commenting out one or the other. My goal is to have the button on screen 1 call screen 2 and vice-versa. My coding background is limited to procedural languages. I'm working with the 'Thinking in C++' books, but this my first exposure to OOP. Can someone help a newbie? Thanks Jeff Elkins int main( int argc, char **argv ) { QPEApplication a( argc, argv ); ScreenOne w; w.setCaption("Gather Input"); w.setGeometry( 0, 15, 240, 320 ); a.setMainWidget( &w ); w.show(); return a.exec(); ScreenTwo z; z.setCaption("Display Calculations"); z.setGeometry( 0, 15, 240, 320 ); a.setMainWidget( &z ); z.show(); return a.exec(); } |
|
|
|
Dec 8 2003, 06:22 AM
Post
#2
|
|
|
Group: Members Posts: 288 Joined: 8-December 03 From: London, UK Member No.: 1,065 |
You should probably only have one main widget but that widget could hold a "QWidgetStack". Quoting from the QT docs:
"The QWidgetStack class provides a stack of widgets, where the user can see only the top widget. The application programmer can move any widget to the top of the stack at any time using the slot raiseWidget(), and add or remove widgets using addWidget() and removeWidget()." My "mainWidget" has the following code in the constructor: editorStack = new QWidgetStack( this ); setCentralWidget( editorStack ); m_annoWin = new CAnnoEdit(editorStack); editorStack->addWidget(m_annoWin, get_unique_id()); m_infoWin = new infowin(editorStack); editorStack->addWidget(m_infoWin, get_unique_id()); CAnnoEdit and infowin are ordinary widgets and editorstack is a pointer to a QWidgetStack which is a member of my main window. I just use (eg) editorStack->raiseWidget( m_infoWin ); to swap between widgets (IIRC I have about 5 widgets in my stack so it should easily cope with your initial two). |
|
|
|
Dec 8 2003, 06:42 AM
Post
#3
|
|
|
Group: Members Posts: 1,176 Joined: 3-October 03 From: UK Member No.: 547 |
You also need to remove that first instance of "return a.exec();" as that is exiting the programme after showing the first widget. That's why you can only show the second one by commenting out the first block.
But as TimW said, you probably want to use the QWidgetStack. |
|
|
|
Dec 8 2003, 02:58 PM
Post
#4
|
|
|
Group: Members Posts: 8 Joined: 8-December 03 Member No.: 1,066 |
Thanks.
Can you recommend some example QWidgetStack code...something that compiles, that I could modify and learn from, but goes beyond 'hello world'? Jeff |
|
|
|
Dec 9 2003, 02:24 AM
Post
#5
|
|
|
Group: Members Posts: 288 Joined: 8-December 03 From: London, UK Member No.: 1,065 |
IIRC the editor app example (might be called textedit?) which comes with the Qtopia SDK is a good example. There is one screen which is a file selector and another which is the actual editor. Neither screen is particularly complex so that reduces the scope for confusion...plus it is where I got my start on widget stacks 8^).
|
|
|
|
Dec 9 2003, 06:42 AM
Post
#6
|
|
|
Group: Posts: 0 Joined: -- Member No.: 0 |
Thanks Tim!
|
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 20th May 2013 - 02:23 PM |