QWidget *QWidget::window() const
Returns the window for this widget, i.e. the next ancestor widget that has (or could have) a window-system frame.
If the widget is a window, the widget itself is returned.
Typical usage is changing the window title:
aWidget->window()->setWindowTitle("New Window Title");
如果小部件是一个窗口,则返回小部件本身
如果小部件在窗口里,则返回该窗口
----------------------------------CODE----------------------------------
qDebug() << this;
qDebug() << this->window();
qDebug() << this->window()->window();
qDebug() << ui->pushButton->window();
qDebug() << ui->pushButton->window()->window();
qDebug() << ui->pushButton->window()->window()->window();
----------------------------------DEBUG----------------------------------
MainWindow(0x7ffdd6fb1060, name="MainWindow")
MainWindow(0x7ffdd6fb1060, name="MainWindow")
MainWindow(0x7ffdd6fb1060, name="MainWindow")
MainWindow(0x7ffdd6fb1060, name="MainWindow")
MainWindow(0x7ffdd6fb1060, name="MainWindow")
MainWindow(0x7ffdd6fb1060, name="MainWindow")