Skip to content
  • 144k Topics
    719k Posts
    S
    My current setup: UserInterfaceElement.h struct UserInterfaceElement { std::unique_ptr<UserInterfaceRenderer> renderer; std::unique_ptr<UiCache> cache; Texture texture; Model model; QString qmlPath; }; UserInterfaceRenderer.h class UserInterfaceRenderer : public QObject { Q_OBJECT public: UserInterfaceRenderer(QWindow* parentWindow = nullptr); ~UserInterfaceRenderer(); void loadQml(const QSize& size, const QString& qmlPath); void render(); void resize(const QSize& size); void createFbo(const QSize& size); void deleteFbo(); QImage grabImage(); // taking screenshot QOpenGLFramebufferObject* getFbo() const { return fbo; } QQuickWindow* getQuickWindow() const { return quickWindow; } void forwardEvent(QEvent* event); QQuickItem* getRootItem() const { return rootItem; } private: QQuickRenderControl* renderControl = nullptr; QQuickWindow* quickWindow = nullptr; QQmlEngine* engine = nullptr; QQmlComponent* component = nullptr; QQuickItem* rootItem = nullptr; QOpenGLFramebufferObject* fbo = nullptr; QOpenGLContext* context = nullptr; QOffscreenSurface* offscreenSurface = nullptr; QSize surfaceSize; }; UserInterfaceRenderer.cpp UserInterfaceRenderer::UserInterfaceRenderer(QWindow* parentWindow) { renderControl = new QQuickRenderControl(this); quickWindow = new QQuickWindow(renderControl); quickWindow->setGraphicsApi(QSGRendererInterface::OpenGL); quickWindow->setFlags( Qt::FramelessWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint | Qt::WindowTransparentForInput ); quickWindow->setColor(Qt::transparent); context = new QOpenGLContext(parentWindow); context->setFormat(parentWindow->format()); context->create(); offscreenSurface = new QOffscreenSurface(); offscreenSurface->setFormat(context->format()); offscreenSurface->create(); context->makeCurrent(offscreenSurface); quickWindow->setGraphicsDevice(QQuickGraphicsDevice::fromOpenGLContext(context)); renderControl->initialize(); quickWindow->create(); //quickWindow->setTransientParent(parentWindow); //quickWindow->setParent(parentWindow); engine = new QQmlEngine(this); if (!engine->incubationController()) { engine->setIncubationController(quickWindow->incubationController()); } } UserInterfaceRenderer::~UserInterfaceRenderer() { if (rootItem) { rootItem->setParentItem(nullptr); delete rootItem; } delete renderControl; delete quickWindow; delete engine; delete component; deleteFbo(); if (context) { context->doneCurrent(); delete context; } if (offscreenSurface) { offscreenSurface->destroy(); delete offscreenSurface; } } void UserInterfaceRenderer::forwardEvent(QEvent* event) { QCoreApplication::sendEvent(quickWindow, event); } void UserInterfaceRenderer::loadQml(const QSize& size, const QString& qmlPath) { component = new QQmlComponent(engine, QUrl::fromLocalFile(qmlPath)); rootItem = qobject_cast<QQuickItem*>(component->create()); if (!rootItem) { qWarning() << "[UserInterfaceRenderer] Failed to load QML root item." << qmlPath; return; } rootItem->setParentItem(quickWindow->contentItem()); rootItem->setSize(size); quickWindow->resize(size); surfaceSize = size; deleteFbo(); createFbo(size); } void UserInterfaceRenderer::resize(const QSize& size) { if (!rootItem) return; rootItem->setSize(size); quickWindow->resize(size); surfaceSize = size; deleteFbo(); createFbo(size); } void UserInterfaceRenderer::createFbo(const QSize& size) { context->makeCurrent(offscreenSurface); QOpenGLFramebufferObjectFormat format; format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); format.setTextureTarget(GL_TEXTURE_2D); format.setInternalTextureFormat(GL_RGBA8); fbo = new QOpenGLFramebufferObject(size, format); QQuickRenderTarget renderTarget = QQuickRenderTarget::fromOpenGLTexture( fbo->texture(), surfaceSize ); quickWindow->setRenderTarget(renderTarget); } void UserInterfaceRenderer::deleteFbo() { if (fbo) { context->makeCurrent(offscreenSurface); delete fbo; fbo = nullptr; } } void UserInterfaceRenderer::render() { if (!rootItem || !quickWindow || !fbo) return; if (!context->makeCurrent(offscreenSurface)) { qWarning() << "Failed to make OpenGL context current!"; return; } QOpenGLFunctions* f = context->functions(); f->glViewport(0, 0, surfaceSize.width(), surfaceSize.height()); f->glClearColor(0, 0, 0, 0); // transparent clear f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); renderControl->beginFrame(); renderControl->polishItems(); renderControl->sync(); renderControl->render(); renderControl->endFrame(); f->glFlush(); } Model.h struct Texture { VkImage image = VK_NULL_HANDLE; VmaAllocation vmaAllocation = VK_NULL_HANDLE; VkImageView imageView = VK_NULL_HANDLE; VkSampler sampler = VK_NULL_HANDLE; uint32_t mipLevels = 0; uint32_t width = 0; uint32_t height = 0; }; struct Material { Texture diffuseTexture; // basic color Texture normalTexture; Texture specularTexture; Texture emissiveTexture; }; struct Mesh { std::vector<Vertex> vertices; std::vector<uint32_t> indices; glm::mat4 transform = glm::mat4(1.0f); Material material; VkBuffer vertexBuffer = VK_NULL_HANDLE; VmaAllocation vertexBufferAllocation = VK_NULL_HANDLE; VkBuffer indexBuffer = VK_NULL_HANDLE; VmaAllocation indexBufferAllocation = VK_NULL_HANDLE; std::vector<VkDescriptorSet> descriptorSets = std::vector<VkDescriptorSet>(MAX_FRAMES_IN_FLIGHT, VK_NULL_HANDLE); }; struct Model { std::vector<Mesh> meshes; ModelType type = ModelType::OTHER; glm::vec3 position; glm::vec3 scale; glm::quat rotation; bool isCollidable = false; }; called in recordCommandBuffer function, which is called each frame for each UI element void AetherEngine::recordUiElementToCommandBuffer(UserInterfaceElement& uiElement, VkCommandBuffer commandBuffer) { renderQmlToTexture(uiElement.renderer.get(), uiElement.texture); vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines["ui"]); recordModelToCommandBuffer(uiElement.model, commandBuffer); } void AetherEngine::renderQmlToTexture(UserInterfaceRenderer* renderer, Texture& texture) { renderer->render(); QImage image = renderer->getFbo()->toImage().convertToFormat(QImage::Format_RGBA8888); if (texture.width != static_cast<uint32_t>(image.width()) || texture.height != static_cast<uint32_t>(image.height())) { cleanupTexture(texture); modelManager.createSolidColorTexture({ 0, 0, 0, 0 }, image.width(), image.height(), texture); } modelManager.uploadRawDataToTexture(image.bits(), image.width(), image.height(), texture); }
  • Jobs, project showcases, announcements - anything that isn't directly development
    4k 23k
    4k Topics
    23k Posts
    S
    This is a community forum. Rarely do people from the Qt company see this. You should ask this question to Qt support directly.
  • Everything related to designing and design tools

    129 392
    129 Topics
    392 Posts
    J
    Using QT Designer might be the simpler route if the main goal is to keep the workflow smooth with Python. QT Design Studio projects often need manual adjustments before they run properly under PySide6.
  • Everything related to the QA Tools

    83 224
    83 Topics
    224 Posts
    B
    I have had a problem when editing the names.py manually in that Squish no longer recognises the object. I now delete the object and re-enter it after using the picker tool then add to object map. Not sure if this is what you meant, but hopefully this helps
  • Everything related to learning Qt.

    390 2k
    390 Topics
    2k Posts
    R
    Re: Introducing the QML for Beginners Learning Path & Challenges! I've completed the first course in this learning path, but I do not know where to access the challenge for the course because there is no enrollment or button to take me to the challenge [image: 569096c7-9018-4000-a4a4-76d4370d5036.png] [image: c3f56111-98ee-4618-8296-2304c987c36e.png]
  • 2k Topics
    13k Posts
    Christian EhrlicherC
    @stash22 said in Why does QTextStream::pos() return -1 while reading a file line-by-line in Qt?: m_readNmeaTextStream.pos() becomes -1. The documentation states this: https://doc.qt.io/qt-6/qtextstream.html#pos
  • 4k Topics
    18k Posts
    K
    Witam Funkcja otrzymuje listę wyrazów do obróbki. Ma sprawdzić czy w wyrazach listy występuje litera char1 . Jeśli wystąpi to usuwa dany wyraz z listy za pomocą metody QString.removeAt(). Nie wiem dlaczego gdy włączona jest metoda funkcja nie usuwa wszystkich wyrazów z literą a. Proszę o pomoc w wyjaśnieniu dlaczego tak się dzieje. QList<QString> MainWindow::searchWord(QList<QString> lista) { QString char1 = ui->lineEdit_6->text(); for( int n = 0; n < lista.size(); n++) { for (int i = 0; i < lista[i].size(); i++) { if(char1 == lista[n][i]) { qDebug() << lista[n]; lista.removeAt(n); } } } qDebug() << lista; return lista; } Tak wygląda wynik działania z metodą removeAt(): "polać" "polał" "polań" "polia" "polja" "polka" "polna" QList("polak", "polan", "polar", "polce", "polec", "poleć", "polej", "polek", "polem", "poleń", "polep", "poler", "polew", "poleź", "poleż", "polik", "polio", "polip", "polis", "poliu", "poliż", "polje", "polji", "polju", "polką", "polkę", "polki", "polko", "polną", "polne", "polni", "polny", "polom", "polon", "polor", "polot", "polub", "poluj") Funkcja pomija polak, polan, polar. Bez metody QString.removeAt(): QList<QString> MainWindow::searchWord(QList<QString> lista) { QString char1 = ui->lineEdit_6->text(); for( int n = 0; n < lista.size(); n++) { for (int i = 0; i < lista[i].size(); i++) { if(char1 == lista[n][i]) { qDebug() << lista[n]; //lista.removeAt(n); } } } qDebug() << lista; return lista; } "polać" "polak" "polał" "polan" "polań" "polar" "polia" "polja" "polka" "polna" QList("polać", "polak", "polał", "polan", "polań", "polar", "polce", "polec", "poleć", "polej", "polek", "polem", "poleń", "polep", "poler", "polew", "poleź", "poleż", "polia", "polik", "polio", "polip", "polis", "poliu", "poliż", "polja", "polje", "polji", "polju", "polka", "polką", "polkę", "polki", "polko", "polna", "polną", "polne", "polni", "polny", "polom", "polon", "polor", "polot", "polub", "poluj")
  • This is where all the posts related to the Qt web services go. Including severe sillyness.
    1k 10k
    1k Topics
    10k Posts
    D
    https://www.youtube.com/watch?v=QXeEoD0pB3E&list=PLsyeobzWxl7poL9JTVyndKe62ieoN-MZ3 Don't know what you need. Youtube series are great. Code along with them to see it working, break it and google what you broke.