我有一个QWidget,并且我有一些Simples Controls,例如Button,ProgressBar,TextEdit等等..在QML中我从QML示例中完成。我正在阅读http://doc.qt.io/archives/qt-4.7/qtbinding.html和http://doc.qt.io/archives/qt-4.7/qml-integration.html 此刻我正在尝试QDeclarativeView。QWidget中的QML小部件
setAttribute(Qt::WA_TranslucentBackground);
layout = new QVBoxLayout(this);
QDeclarativeView* btnView = new QDeclarativeView;
btnView->setSource(QUrl::fromLocalFile("Button.qml"));
QObject* btnObj = btnView->rootObject();
btnObj->setProperty("width", 140);
btnObj->setProperty("height", 32);
btnObj->setProperty("text", "Close");
//progressBar = new QProgressBar(this);
button = new QPushButton("Click", this);
//layout->addWidget(progressBar);
layout->addWidget(button);
btnView->setGeometry(0, 0, 140, 32);
btnView->setBaseSize(140, 32);
layout->addWidget(btnView);
setLayout(layout);
为什么我btnView正在这个很多空间?也是它(QDeclarativeView)一个好方法吗?或者有更好的解决方案?
当使用QDeclarativeComponent时,我得到一个QObject。但不是QWidget。这甚至是一个好的解决方案?在传统的QWidget中有什么最好的解决方案来获得丰厚的简单Widget?