两个同级的Rectangle,一个是大窗口,一个是小窗口,小的Rectangle默认visible是false,当点击某个按钮时,怎么让它覆盖在大Rectangle的某一部分并显示出来。当点击某个按钮时,我把小Rectangle的默认visible改成true没有作用,求教。
1条回答 默认 最新
- qtchen_1988 2019-07-22 12:14关注
main.cpp
#include <QApplication> #include <QQuickView> int main(int argc, char *argv[]) { QApplication app(argc, argv); QQuickView view; view.setSource(QUrl(QStringLiteral("qrc:/main.qml"))); view.show(); return app.exec(); }
main.qml
import QtQuick 2.4 import QtQuick.Controls 1.3 Rectangle{ id: root width: 800 height: 480 color: "#00B000" function btnsig_handling(){ smallId.x = bigId.x; smallId.y = 40; smallId.z = bigId.z+0.1; smallId.visible = true; } Rectangle{ id: smallId width: 180 height: 80 color: "yellow" visible: false x: 450 y:10 } Rectangle{ id: bigId width: 400 height: 300 x: 10 y: 10 color: "blue" } Button { y: root.height - height width: 100 height: 30 text: "Click me" onClicked: { root.btnsig_handling(); } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 3无用