Hi, I have a problem with changing the window name and central widget in Qt. There is MainWindow:
class MainWindow : public QMainWindow
{
QStackedWidget* widgets;
Quiz* widget1, *widget2;
}
and there is a Quiz class:
class Quiz : public QWidget
{
public slots:
void myClicked();
}
I wanted to change the MainWindow title after clicking the button, which is a Quiz element (and connected to the myClicked slot).
void Quiz::myClicked()
{
static_cast<MainWindow>(parent).myFunction();
}
void MainWindow::myFunction()
{
widget2 = new Quiz(this,2);
widgets->addWidget(widget2);
std::cout<<"current wdgt: " << widgets->currentIndex() << std::endl;
widgets->setCurrentWidget(widget2);
std::cout<<"current wdgt " << widgets->currentIndex() << std::endl;
setWindowTitle("newTitle");
std::cout<<"Title is " << windowTitle().toStdString() << std::endl;
}
So widgets-> currentIndex shows the index of the new widget, but nothing changes in my window. The same problem is related to the window name - the windowTitle () method returns a new title, but the title in the title bar is old. What for? If I change the name in Quiz :: myClicked by:
parent->setWindowTitle("newTitle");
it works! Why does it work, how weird? Please help.
source
share