PDA

View Full Version : Navigation between windows



masmic
4th March 2016, 10:31
Hi to everyone,

I come from Java and I'm doing my first steps into QT. I'm using the designer to develop an app that has multiple windows and I have to navigate between them. To clarify a bit more this, I'm developing a kind of Car Infotainment System, where I have some buttons on the left, and each of these buttones sends me to different windows (media, radio, GPS, etc...)

My problem is that I don't know how to navigate between theses windows. After reading a lot, I've find that QStackedWidget could do the job, but this works using indexes and navigating left-right through the widgets. What I need is that each button I press sends me to a determided window.

In android, I would create a frameContainer ant the right side and then programmatically change the layout each time I press a button, but I'm very lost here, I don't find complete examples of how to do this.

So I'm not asking you a complete tutorial of how to doing this, just give me some steps of what to use and how to use it to be able to continue.

Thanks.

anda_skoa
4th March 2016, 10:49
I come from Java and I'm doing my first steps into QT. I'm using the designer to develop an app that has multiple windows and I have to navigate between them. To clarify a bit more this, I'm developing a kind of Car Infotainment System, where I have some buttons on the left, and each of these buttones sends me to different windows (media, radio, GPS, etc...)

That sounds more like you have a single window with the content changing depending on state.



What I need is that each button I press sends me to a determided window.

That is exactly what QStackedWidget does: you tell it which of its page it should show and it shows that one.

You can either set the widget to show in a slots connected to the buttons or use a QSignalMapper to map from button to which widgets to show.

Cheers,
_

P.S.: for touch based embedded devices the technology of choice is often QtQuick instead of QtWidgets, as it makes "phone like" experience easier to achieve

masmic
4th March 2016, 11:35
So QStackedWidget could do the job? I thought that I could only change pages with the left-right arrows. Is there any tutorial or example of this behaviour?

Lesiok
4th March 2016, 11:54
Look at "Config Dialog Example" in Qt examples.

masmic
4th March 2016, 12:09
Thanks! But could I do this using the designer? Os theses things must be done coding?

anda_skoa
4th March 2016, 12:10
So QStackedWidget could do the job? I thought that I could only change pages with the left-right arrows.

Where does QStackedWidget::setCurrentIndex() or QStackedWidget::setCurrentWidget() say anything about left-right arrows?

Cheers,
_

masmic
4th March 2016, 13:57
Where does QStackedWidget::setCurrentIndex() or QStackedWidget::setCurrentWidget() say anything about left-right arrows?

Cheers,
_

I just tell that because when adding it in the designer it shows by default thos arrows

anda_skoa
4th March 2016, 14:56
I just tell that because when adding it in the designer it shows by default thos arrows
Yes, so that you can conveniently switch between pages in designer.

The stacked widget does not have any UI of its own, it just shows its pages.
You can easily see this if you preview the form.

In a real application one most often does not add pages in designer but design each page and then put instances of them into the stack in code.

Cheers,
_