Unsolved Basics. How to use <a href> equivalent to display new content?
-
thank you for your reply
it is getting working and now it works finally with the combobox -
QPushButton and setCurrentIndex(int) slot.
No, I can not use the above. The mainwindow constructor which seems to be a designer doesn't seem to have that option in a list for a pushbutton item.
-
@Andrey-Volodin Well, setCurrentIndex(int) needs a parameter, so you cannot connect the push button directly. But you can add a slot in main window, connect it to the push button and in this slot call setCurrentIndex(int).
-
https://github.com/AndreV84/pilot
it seems that there should be 4 objects defined:
button , the main window, stack widget , as in
http://doc.qt.io/qt-4.8/signalsandslots.html
how to add trigger? comparator? logical + or -? -
@Andrey-Volodin said in Basics. How to use <a href> equivalent to display new content?:
how to add trigger
What trigger do you mean?
-
on button press a call is passed to a slot
how to make the slot to change stackWidget page on the button press
https://en.wikipedia.org/wiki/Event-driven_programming
https://en.wikipedia.org/wiki/Schmitt_trigger
it seems that the button and the stackwidget are always in separate sets, despite a new slot and a new signal created -
@Andrey-Volodin Not sure I understand the problem. Did you read http://doc.qt.io/qt-5.8/signalsandslots.html ?
You just define a slot in lets say MainWindow:// Header class MainWindow: { private slots: void onButtonPressed(); }; // cpp MainWindow::MainWindow() { connect(ui->pushButton, SIGNAL(clicked(bool)), this, SLOT(onButtonPressed())); } void MainWindow::onButtonPressed() { int pageToShow = 1; // you need to find out what the next index is ui->stackedWidget->setCurrentIndex(pageToShow); }
"it seems that the button and the stackwidget are always in separate sets, despite a new slot and a new signal created" - sorry, I don't understand. What do you mean by "sets"?
-
https://en.wikipedia.org/wiki/Set_(mathematics)
I used to read: http://doc.qt.io/qt-4.8/signalsandslots.html , which seems to be a mirror of the link http://doc.qt.io/qt-5.8/signalsandslots.html .
I tried to perform the task in Designer, without sources editing manually. It doesnt appear to seem possible. -
@Andrey-Volodin
https://en.wikipedia.org/wiki/Set_(mathematics) - still don't understand what you mean with sets in this particular context.
In designer you can connect existing signals/slots. You can even define a new slot in Designer, but you have to implement it by yourself.
That means: add slot to main window in Designer, connect this slot to the clicked() signal of your push button in Designer, implement the slot in main window. -
@jsulm said in Basics. How to use <a href> equivalent to display new content?:
In designer you can connect existing signals/slots. You can even define a new slot in Designer, but you have to implement it by yourself.
That means: add slot to main window in Designer, connect this slot to the clicked() signal of your push button in Designer, implement the slot in main window.The above is what I have done ;
How to connect the stackWidgets call with the above?
What do you mean saying "implement the slot in mine window" ? -
@Andrey-Volodin You mean setCurrentIndex()? I did it in the example above.
What I mean with implement: write the body of the slot since Designer does not know what you want to do in the slot. From my example above:// You have to write this code even if you added the slot in Designer void MainWindow::onButtonPressed() { int pageToShow = 1; // you need to find out what the next index is ui->stackedWidget->setCurrentIndex(pageToShow); }