Skip to content
QtWS25 Call for Papers
  • 0 Votes
    2 Posts
    120 Views
    B

    @ian28 the way you are doing it is how one would implement a new QML component in C++ that would tend to be purely used in QML - i.e. you wouldn't normally interact with it from the C++ side once it is created.

    If you wanted to continue with that sort of approach, it might be better to create the timer in QML and have that update the path of your Image.

    However a better fit might be to expose your "model" via a "singleton instance" (see qmlRegisterSingletonInstance). This is the more modern approach that is advised rather than using the older setContextProperty, but you will probably find more information out there about using setContextProperty. It's not massively different in principle and it might be easier for you to use the older approach in order to get started.

  • 0 Votes
    3 Posts
    191 Views
    V

    @JoeCFD great!! Will start experimenting

  • 0 Votes
    1 Posts
    104 Views
    No one has replied
  • 0 Votes
    15 Posts
    2k Views
    JoeCFDJ

    @SeeRich
    can you change

    setAttribute(Qt::WA_StyledBackground); setObjectName( "mainWindow" ); setStyleSheet( QString( "MainWindow#%1 { background-color: blue; }" ) .arg( objectName() );

    to

    setAttribute(Qt::WA_StyledBackground); setObjectName( "mainWindow" ); setStyleSheet( QString( "QWidget#%1 { background-color: blue; }" ) .arg( objectName() );

    there is no MainWindow stylesheet. It should be QMainWindow.

  • 0 Votes
    5 Posts
    291 Views
    N

    @wrosecrans
    I know that I need them. But don‘t know how to apply them on the scene and keep everything thats on that. I thought that the rect itself has the points in it using the render function of the QGraphicsScene is enough.

    What I do: I set the DragMode of the QGraphicsView to rubberband so the user can select some part pf the scene by simply dragging. The returned rect is now sent to the view to get the underlying image of the scene.

  • 0 Votes
    3 Posts
    573 Views
    M

    @Christian-Ehrlicher Thanks a lot, it is exactly what I was missing!

  • 0 Votes
    12 Posts
    7k Views
    C

    @J-Hilk said in How can I make my app ignore window's "HIGH DPI SCALING"?:

    [Platforms]
    WindowsArguments = dpiawareness=0

    Thank you! I tried to used this before but I've put incorrect syntax in this file. This works.

  • 0 Votes
    9 Posts
    891 Views
    timob256T

    main.cpp

    #include "widget.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; w.show(); return a.exec(); }

    QTOgreWindow.cpp

    #include "QTOgreWindow.h" #if OGRE_VERSION >= ((2 << 16) | (0 << 8) | 0) #include <Compositor/OgreCompositorManager2.h> #endif /* Note that we pass any supplied QWindow parent to the base QWindow class. This is necessary should we need to use our class within a container. */ QTOgreWindow::QTOgreWindow(QWindow *parent) : QWindow(parent) , m_update_pending(false) , m_animating(false) , m_ogreRoot(NULL) , m_ogreWindow(NULL) , m_ogreCamera(NULL) , m_cameraMan(NULL) { setAnimating(true); installEventFilter(this); m_ogreBackground = Ogre::ColourValue(0.0f, 0.5f, 1.0f); } /* Upon destruction of the QWindow object we destroy the Ogre3D scene. */ QTOgreWindow::~QTOgreWindow() { if (m_cameraMan) delete m_cameraMan; delete m_ogreRoot; } /* In case any drawing surface backing stores (QRasterWindow or QOpenGLWindow) of Qt are supplied to this class in any way we inform Qt that they will be unused. */ void QTOgreWindow::render(QPainter *painter) { Q_UNUSED(painter); } /* Our initialization function. Called by our renderNow() function once when the window is first exposed. */ void QTOgreWindow::initialize() { /* As shown Ogre3D is initialized normally; just like in other documentation. */ #ifdef _MSC_VER m_ogreRoot = new Ogre::Root(Ogre::String("plugins" OGRE_BUILD_SUFFIX ".cfg")); #else m_ogreRoot = new Ogre::Root(Ogre::String("plugins.cfg")); #endif Ogre::ConfigFile ogreConfig; /* Commended out for simplicity but should you need to initialize resources you can do so normally. ogreConfig.load("resources/resource_configs/resources.cfg"); Ogre::ConfigFile::SectionIterator seci = ogreConfig.getSectionIterator(); Ogre::String secName, typeName, archName; while (seci.hasMoreElements()) { secName = seci.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { typeName = i->first; archName = i->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName); } } */ const Ogre::RenderSystemList& rsList = m_ogreRoot->getAvailableRenderers(); Ogre::RenderSystem* rs = rsList[0]; /* This list setup the search order for used render system. */ Ogre::StringVector renderOrder; #if defined(Q_OS_WIN) renderOrder.push_back("Direct3D9"); renderOrder.push_back("Direct3D11"); #endif renderOrder.push_back("OpenGL"); renderOrder.push_back("OpenGL 3+"); for (Ogre::StringVector::iterator iter = renderOrder.begin(); iter != renderOrder.end(); iter++) { for (Ogre::RenderSystemList::const_iterator it = rsList.begin(); it != rsList.end(); it++) { if ((*it)->getName().find(*iter) != Ogre::String::npos) { rs = *it; break; } } if (rs != NULL) break; } if (rs == NULL) { if (!m_ogreRoot->restoreConfig()) { // if (!m_ogreRoot->showConfigDialog()) // OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, // "Abort render system configuration", // "QTOgreWindow::initialize"); } } /* Setting size and VSync on windows will solve a lot of problems */ QString dimensions = QString("%1 x %2").arg(this->width()).arg(this->height()); rs->setConfigOption("Video Mode", dimensions.toStdString()); rs->setConfigOption("Full Screen", "No"); rs->setConfigOption("VSync", "Yes"); m_ogreRoot->setRenderSystem(rs); m_ogreRoot->initialise(false); Ogre::NameValuePairList parameters; /* Flag within the parameters set so that Ogre3D initializes an OpenGL context on it's own. */ if (rs->getName().find("GL") <= rs->getName().size()) parameters["currentGLContext"] = Ogre::String("false"); /* We need to supply the low level OS window handle to this QWindow so that Ogre3D knows where to draw the scene. Below is a cross-platform method on how to do this. If you set both options (externalWindowHandle and parentWindowHandle) this code will work with OpenGL and DirectX. */ #if defined(Q_OS_MAC) || defined(Q_OS_WIN) parameters["externalWindowHandle"] = Ogre::StringConverter::toString((size_t)(this->winId())); parameters["parentWindowHandle"] = Ogre::StringConverter::toString((size_t)(this->winId())); #else parameters["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned long)(this->winId())); parameters["parentWindowHandle"] = Ogre::StringConverter::toString((unsigned long)(this->winId())); #endif #if defined(Q_OS_MAC) parameters["macAPI"] = "cocoa"; parameters["macAPICocoaUseNSView"] = "true"; #endif /* Note below that we supply the creation function for the Ogre3D window the width and height from the current QWindow object using the "this" pointer. */ m_ogreWindow = m_ogreRoot->createRenderWindow("QT Window", this->width(), this->height(), false, &parameters); m_ogreWindow->setVisible(true); /* The rest of the code in the initialization function is standard Ogre3D scene code. Consult other tutorials for specifics. */ #if OGRE_VERSION >= ((2 << 16) | (0 << 8) | 0) const size_t numThreads = std::max<int>(1, Ogre::PlatformInformation::getNumLogicalCores()); Ogre::InstancingThreadedCullingMethod threadedCullingMethod = Ogre::INSTANCING_CULLING_SINGLETHREAD; if (numThreads > 1)threadedCullingMethod = Ogre::INSTANCING_CULLING_THREADED; m_ogreSceneMgr = m_ogreRoot->createSceneManager(Ogre::ST_GENERIC, numThreads, threadedCullingMethod); #else m_ogreSceneMgr = m_ogreRoot->createSceneManager(Ogre::ST_GENERIC); #endif m_ogreCamera = m_ogreSceneMgr->createCamera("MainCamera"); m_ogreCamera->setPosition(Ogre::Vector3(0.0f, 0.0f, 10.0f)); m_ogreCamera->lookAt(Ogre::Vector3(0.0f, 0.0f, -300.0f)); m_ogreCamera->setNearClipDistance(0.1f); m_ogreCamera->setFarClipDistance(200.0f); m_cameraMan = new OgreQtBites::SdkQtCameraMan(m_ogreCamera); // create a default camera controller #if OGRE_VERSION >= ((2 << 16) | (0 << 8) | 0) createCompositor(); #else Ogre::Viewport* pViewPort = m_ogreWindow->addViewport(m_ogreCamera); pViewPort->setBackgroundColour(m_ogreBackground); #endif m_ogreCamera->setAspectRatio( Ogre::Real(m_ogreWindow->getWidth()) / Ogre::Real(m_ogreWindow->getHeight())); m_ogreCamera->setAutoAspectRatio(true); Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); createScene(); m_ogreRoot->addFrameListener(this); } void QTOgreWindow::createScene() { /* Example scene Derive this class for your own purpose and overwite this function to have a working Ogre widget with your own content. */ m_ogreSceneMgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f)); #if OGRE_VERSION >= ((2 << 16) | (0 << 8) | 0) Ogre::Entity* sphereMesh = m_ogreSceneMgr->createEntity(Ogre::SceneManager::PT_SPHERE); #else Ogre::Entity* sphereMesh = m_ogreSceneMgr->createEntity("mySphere", Ogre::SceneManager::PT_SPHERE); #endif Ogre::SceneNode* childSceneNode = m_ogreSceneMgr->getRootSceneNode()->createChildSceneNode(); childSceneNode->attachObject(sphereMesh); Ogre::MaterialPtr sphereMaterial = Ogre::MaterialManager::getSingleton().create("SphereMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true); sphereMaterial->getTechnique(0)->getPass(0)->setAmbient(0.1f, 0.1f, 0.1f); sphereMaterial->getTechnique(0)->getPass(0)->setDiffuse(0.2f, 0.2f, 0.2f, 1.0f); sphereMaterial->getTechnique(0)->getPass(0)->setSpecular(0.9f, 0.9f, 0.9f, 1.0f); //sphereMaterial->setAmbient(0.2f, 0.2f, 0.5f); //sphereMaterial->setSelfIllumination(0.2f, 0.2f, 0.1f); sphereMesh->setMaterialName("SphereMaterial"); childSceneNode->setPosition(Ogre::Vector3(0.0f, 0.0f, 0.0f)); childSceneNode->setScale(Ogre::Vector3(0.01f, 0.01f, 0.01f)); // Radius, in theory. #if OGRE_VERSION >= ((2 << 16) | (0 << 8) | 0) Ogre::SceneNode* pLightNode = m_ogreSceneMgr->getRootSceneNode()->createChildSceneNode(); Ogre::Light* light = m_ogreSceneMgr->createLight(); pLightNode->attachObject(light); pLightNode->setPosition(20.0f, 80.0f, 50.0f); #else Ogre::Light* light = m_ogreSceneMgr->createLight("MainLight"); light->setPosition(20.0f, 80.0f, 50.0f); #endif } #if OGRE_VERSION >= ((2 << 16) | (0 << 8) | 0) void QTOgreWindow::createCompositor() { /* Example compositor Derive this class for your own purpose and overwite this function to have a working Ogre widget with your own compositor. */ Ogre::CompositorManager2* compMan = m_ogreRoot->getCompositorManager2(); const Ogre::String workspaceName = "default scene workspace"; const Ogre::IdString workspaceNameHash = workspaceName; compMan->createBasicWorkspaceDef(workspaceName, m_ogreBackground); compMan->addWorkspace(m_ogreSceneMgr, m_ogreWindow, m_ogreCamera, workspaceNameHash, true); } #endif void QTOgreWindow::render() { /* How we tied in the render function for OGre3D with QWindow's render function. This is what gets call repeatedly. Note that we don't call this function directly; rather we use the renderNow() function to call this method as we don't want to render the Ogre3D scene unless everything is set up first. That is what renderNow() does. Theoretically you can have one function that does this check but from my experience it seems better to keep things separate and keep the render function as simple as possible. */ // Ogre::WindowEventUtilities::messagePump(); m_ogreRoot->renderOneFrame(); } void QTOgreWindow::renderLater() { /* This function forces QWindow to keep rendering. Omitting this causes the renderNow() function to only get called when the window is resized, moved, etc. as opposed to all of the time; which is generally what we need. */ if (!m_update_pending) { m_update_pending = true; QApplication::postEvent(this, new QEvent(QEvent::UpdateRequest)); } } bool QTOgreWindow::event(QEvent *event) { /* QWindow's "message pump". The base method that handles all QWindow events. As you will see there are other methods that actually process the keyboard/other events of Qt and the underlying OS. Note that we call the renderNow() function which checks to see if everything is initialized, etc. before calling the render() function. */ switch (event->type()) { case QEvent::UpdateRequest: m_update_pending = false; renderNow(); return true; default: return QWindow::event(event); } } /* Called after the QWindow is reopened or when the QWindow is first opened. */ void QTOgreWindow::exposeEvent(QExposeEvent *event) { Q_UNUSED(event); if (isExposed()) renderNow(); } /* The renderNow() function calls the initialize() function when needed and if the QWindow is already initialized and prepped calls the render() method. */ void QTOgreWindow::renderNow() { if (!isExposed()) return; if (m_ogreRoot == NULL) { initialize(); } render(); if (m_animating) renderLater(); } /* Our event filter; handles the resizing of the QWindow. When the size of the QWindow changes note the call to the Ogre3D window and camera. This keeps the Ogre3D scene looking correct. */ bool QTOgreWindow::eventFilter(QObject *target, QEvent *event) { if (target == this) { if (event->type() == QEvent::Resize) { if (isExposed() && m_ogreWindow != NULL) { m_ogreWindow->resize(this->width(), this->height()); } } } return false; } /* How we handle keyboard and mouse events. */ void QTOgreWindow::keyPressEvent(QKeyEvent * ev) { if(m_cameraMan) m_cameraMan->injectKeyDown(*ev); } void QTOgreWindow::keyReleaseEvent(QKeyEvent * ev) { if(m_cameraMan) m_cameraMan->injectKeyUp(*ev); } void QTOgreWindow::mouseMoveEvent( QMouseEvent* e ) { static int lastX = e->x(); static int lastY = e->y(); int relX = e->x() - lastX; int relY = e->y() - lastY; lastX = e->x(); lastY = e->y(); if(m_cameraMan && (e->buttons() & Qt::LeftButton)) m_cameraMan->injectMouseMove(relX, relY); } void QTOgreWindow::wheelEvent(QWheelEvent *e) { if(m_cameraMan) m_cameraMan->injectWheelMove(*e); } void QTOgreWindow::mousePressEvent( QMouseEvent* e ) { if(m_cameraMan) m_cameraMan->injectMouseDown(*e); } void QTOgreWindow::mouseReleaseEvent( QMouseEvent* e ) { if(m_cameraMan) m_cameraMan->injectMouseUp(*e); QPoint pos = e->pos(); Ogre::Ray mouseRay = m_ogreCamera->getCameraToViewportRay( (Ogre::Real)pos.x() / m_ogreWindow->getWidth(), (Ogre::Real)pos.y() / m_ogreWindow->getHeight()); Ogre::RaySceneQuery* pSceneQuery = m_ogreSceneMgr->createRayQuery(mouseRay); pSceneQuery->setSortByDistance(true); Ogre::RaySceneQueryResult vResult = pSceneQuery->execute(); for (size_t ui = 0; ui < vResult.size(); ui++) { if (vResult[ui].movable) { if (vResult[ui].movable->getMovableType().compare("Entity") == 0) { emit entitySelected((Ogre::Entity*)vResult[ui].movable); } } } m_ogreSceneMgr->destroyQuery(pSceneQuery); } /* Function to keep track of when we should and shouldn't redraw the window; we wouldn't want to do rendering when the QWindow is minimized. This takes care of those scenarios. */ void QTOgreWindow::setAnimating(bool animating) { m_animating = animating; if (animating) renderLater(); } bool QTOgreWindow::frameRenderingQueued(const Ogre::FrameEvent& evt) { m_cameraMan->frameRenderingQueued(evt); return true; } void QTOgreWindow::log(Ogre::String msg) { if(Ogre::LogManager::getSingletonPtr() != NULL) Ogre::LogManager::getSingletonPtr()->logMessage(msg); } void QTOgreWindow::log(QString msg) { log(Ogre::String(msg.toStdString().c_str())); }

    widget.cpp

    #include "widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) { QTOgreWindow * ogreWindow = new QTOgreWindow (); ogreWindow->show (); } Widget::~Widget() { }

    plugin.cfg

    # Defines plugins to load # Define plugin folder PluginFolder=/usr/local/lib/OGRE # Define plugins # Plugin=RenderSystem_Direct3D9 # Plugin=RenderSystem_Direct3D11 Plugin=RenderSystem_GL Plugin=RenderSystem_GL3Plus Plugin=RenderSystem_GLES2 # Plugin=RenderSystem_Metal # Plugin=RenderSystem_Tiny Plugin=Plugin_ParticleFX Plugin=Plugin_BSPSceneManager # Plugin=Plugin_CgProgramManager Plugin=Codec_EXR Plugin=Codec_STBI # Plugin=Codec_FreeImage Plugin=Plugin_PCZSceneManager Plugin=Plugin_OctreeZone Plugin=Plugin_OctreeSceneManager Plugin=Plugin_DotScene # Plugin=Codec_Assimp

    Screenshot_20211208_120343.png

    the first part of the answer at the top (failed to fit into one message)

  • 0 Votes
    8 Posts
    1k Views
    artwawA

    @jsulm That came to my mind too but considering that all the other parts of Ui work - push buttons, tool buttons, all the actions associated with tool buttons and menu, two table views with sql table models, status bar displays status tips on hover over elements... I had to ditch that idea.

  • 0 Votes
    2 Posts
    272 Views
    O

    The problem arises from the usage of the method m_model.setStringList(). The latter always clear the previous data, hence the index always reset upon its call.

    Solution:

    Use m_model.setStringList() only in the constructor to init the model.

    After that manually insert the row on the model and set the data for the respective row. This can be achieved with a simple modification in the slot method.

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); m_model.setStringList({"1","2"}); ui->comboBox->setModel(&model); } void MainWindow::on_pushButton_clicked() { m_model.insertRow(model.rowCount()); m_model.setData(model.index(model.rowCount()-1), "3"); }

    In the example above, "3" is appended to the list model without changing the current index from the QComboBox.

  • 0 Votes
    4 Posts
    364 Views
    Thank YouT

    @activeLearner
    There are many ways to do it

    StackedWidgets
    It is simplest way to do the things that you have said. It may take memory but it is easiest method to solve this.
    How it works
    First Create buttons
    Add stacked widgets then you can create specific widgets such as human elephant in living beings. (You can promote widgets in ui too)
    Again you can add another stacked widgets inside that widget so it's most easy way to do so
    https://doc.qt.io/qt-5/qstackedwidget.html Simple dialogs || windows
    You can create windows on clicking the buttons and again inside it you can do same and achieve it. I don't recommend it as it looks so untidy 3.tabWidget
    It's similar to stacked widgets but it looks more like your browser tabs
    You can create tabWidget inside it and do same for more deep
    https://doc.qt.io/qt-5/qtwidgets-dialogs-tabdialog-example.html 4.Simple Widgets
    Another approach to get this is you can simply create widgets and
    use setVisible property to show on the basis of user clicks

    There is nothing that is best option. I like stackedWidget the most and can handle almost all things for simple development

  • 0 Votes
    1 Posts
    282 Views
    No one has replied
  • 0 Votes
    15 Posts
    1k Views
    Christian EhrlicherC

    @continue98 said in What is required for link Widgets?:

    QXcbIntegration

    this is a separate plugin / library which you don't link against as it seems.

  • 0 Votes
    6 Posts
    1k Views
    P

    @SGaist
    It's not enabled by default but it's available as a widget that you can place on the panel.
    Please tell me if I'm wrong here:
    Each application is given an area in the framebuffer to do its drawings and WM place additional window borders , shadows , effects and some handles to control windows.
    But I wonder how can WM separate toolbars from the window ? Are toolbars placed on some queue or special buffer which is visible to WM and DE(to use with the global menu widget)?

  • 0 Votes
    3 Posts
    2k Views
    J

    I see, thanks for the response.

    I stumbled today on an old thread where user wanted the same font rendering as in Photoshop. One of person responding said that they made their own wrapper of FreeType. I guess I will try to render icons using that and see where it goes.

    Not gonna mark it as solved for now though, maybe someone will stumble on it with some experience.

  • 0 Votes
    2 Posts
    308 Views
    F

    Just found out about QSortFilterProxyModel::filterAcceptsColumn which provides an integer for the column-index and hence suits my usecase perfectly. Still unsure why I couldn't get it to work with map(From/To)Source though

  • 0 Votes
    3 Posts
    463 Views
    M

    Same problem exactly here, did you find any solution ?

  • 0 Votes
    3 Posts
    1k Views
    M

    Thanks for the input! I think I'm going to go with QGraphicsView for the notation and use QQuickWidgets throughout the other pieces of the UI that don't need access to the entire model. I'm hoping that won't be too complicated and will give me the best of both worlds. But I do wonder: is there a specific piece of Qt Quick that's supposed to a "replacement" for QGraphicsView? It seems like the scene graph is a bit too low level, but it's also the only way to gain a lot of control and keep things mostly on the C++ side. It would be nice if the built-in QML elements are exposed via a C++ API at some point.

  • 0 Votes
    1 Posts
    990 Views
    No one has replied
  • 0 Votes
    1 Posts
    347 Views
    No one has replied