Merhabalar.
Geçenlerde Qt3D ile arayüz üzerinde 3D nesneleri görüntüleyebileceğim bir örneğe rastladım.
Kodun kısaltılmış hali:
import sys
from PySide2 import QtWidgets, QtCore, QtGui
from PySide2.Qt3DCore import Qt3DCore
from PySide2.Qt3DExtras import Qt3DExtras
from PySide2.Qt3DRender import Qt3DRender
from PySide2.Qt3DInput import Qt3DInput
class SceneModifier(QtCore.QObject):
def __init__(self, root_entity=None):
super().__init__()
self.m_rootEntity = root_entity
self.cuboid = Qt3DExtras.QCuboidMesh()
self.cuboidTransform = Qt3DCore.QTransform(scale=4.0, translation=QtGui.QVector3D(5.0, -4.0, 0.0))
self.cuboidMaterial = Qt3DExtras.QPhongMaterial(diffuse=QtGui.QColor("#665423"))
self.m_cuboidEntity = Qt3DCore.QEntity(self.m_rootEntity)
self.m_cuboidEntity.addComponent(self.cuboid)
self.m_cuboidEntity.addComponent(self.cuboidMaterial)
self.m_cuboidEntity.addComponent(self.cuboidTransform)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
view = Qt3DExtras.Qt3DWindow()
view.defaultFrameGraph().setClearColor(QtGui.QColor("#4d4d4f"))
container = QtWidgets.QWidget.createWindowContainer(view)
screenSize = view.screen().size()
container.setMinimumSize(QtCore.QSize(200, 200))
container.setMaximumSize(screenSize)
widget = QtWidgets.QWidget()
hLayout = QtWidgets.QHBoxLayout(widget)
vLayout = QtWidgets.QVBoxLayout()
vLayout.setAlignment(QtCore.Qt.AlignTop)
hLayout.addWidget(container, 1)
hLayout.addLayout(vLayout)
widget.setWindowTitle("Basic shapes")
input_ = Qt3DInput.QInputAspect()
view.registerAspect(input_)
rootEntity = Qt3DCore.QEntity()
cameraEntity = view.camera()
cameraEntity.lens().setPerspectiveProjection(45.0, 16.0 / 9.0, 0.1, 1000.0)
cameraEntity.setPosition(QtGui.QVector3D(0, 0, 20.0))
cameraEntity.setUpVector(QtGui.QVector3D(0, 1, 0))
cameraEntity.setViewCenter(QtGui.QVector3D(0, 0, 0))
lightEntity = Qt3DCore.QEntity(rootEntity)
light = Qt3DRender.QPointLight(lightEntity)
light.setColor("white")
light.setIntensity(1)
lightEntity.addComponent(light)
lightTransform = Qt3DCore.QTransform(lightEntity)
lightTransform.setTranslation(cameraEntity.position())
lightEntity.addComponent(lightTransform)
modifier = SceneModifier(rootEntity)
view.setRootEntity(rootEntity)
info = QtWidgets.QCommandLinkButton()
info.setText("Qt3D ready-made meshes")
info.setDescription("Bla bla bla.")
info.setIconSize(QtCore.QSize(0, 0))
vLayout.addWidget(info)
widget.show()
widget.resize(1200, 800)
sys.exit(app.exec_())
-
Burada
QHBoxLayout()
kullanılmasından ötürü olmalı ki, 3D nesnenin içinde yer aldığı bölge çok büyük oluyor. Bunucontainer.setMaximumSize(QtCore.QSize(400, 400))
ile ayarlayabilsem de bu bölgenin konumunu x ve y değerleri olarak değiştirmeyi beceremedim. -
Yardıma ihtiyaç duyduğum nokta şu,
ben bu bahsini ettiğim bölgenin,setGeometry(QRect(25, 25, 400, 400))
ile konumunu ve boyutunu ayarlamak istiyorum.
Fakat buQHBoxLayout()
tüm planlarımı mahvediyor gibi görünüyor.
Bahsini ettiğim yöntemle veya başka yöntemlerle, bu pencerenin konumunu nasıl ayarlayabileceğimi gösterebilirseniz çok mutlu olurum.