Qt獲取控制元件的大小,以及主視窗大小為什麼一樣大小
阿新 • • 發佈:2018-12-12
MainWindow::MainWindow(QWidget *parent)
: QWidget(parent)
{ QPushButton *button = new QPushButton(tr("abc"));
HelloWorld *m_hello = new HelloWorld(this);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(button, 0, 0);
layout->addWidget(m_hello, 1, 0);
QRect rc3 = button->rect();
qDebug() << "--1--" << rc3;
QRect rc4 = m_hello->rect();
qDebug() << "--2--" << rc4;
QRect rc5 = geometry();
qDebug() << "--3--" << rc5;
}
注:HelloWorld繼承自QTextEdit的一個類
列印:
--1-- QRect(0,0 640x480)
--2-- QRect(0,0 640x480)
--3-- QRect(0,0 640x480)