Normal (desktop) user-interface controls with QML?
I'm currently porting one of my applications to C++ with QT as a GUI. The QML-samples look pretty darn good, but the user-interface contro开发者_开发知识库ls don't look like the normal ones on Windows and MacOS.
I would like to use the many cool features QML offers (like animations), but also have controls which look similar to the normal ones (as if I'd use standard QT).
Can I find some styled QML-controls somewhere or which approach would you recommend.
Hedge, there are 2 reasons why your UI didn't look native:
1) Qt Quick (QML) now is in a stage when only basic primitives are available. That means there are no actual UI elements (like Button, Tool Bar, etc.) available yet. There are just some of them like list views which are included in the basic set of components. There is some work that is going on by Qt guys and you can find some of the desktop components that are available here:
http://qt.gitorious.org/qt-components/desktop
Those will be look native on you desktop but they are in a very early and unstable stage at this moment.
2) Qt Quick (QML) is developed by a company named Qt Development Frameworks (former Trolltech) owned by Nokia which is in its turn is one of the largest cell phone manufactures in the world. Qt Quick is created for touch user interfaces on mobile and embedded platforms and initially was targeted for MeeGo platform. A set of QML components for MeeGo is being developed but according to Qt Development Frameworks blog is not available to the public by marketing reasons. The version that is available to the public is not outdated but you can get some idea about what is going on. Its available here:
http://qt.gitorious.org/qt-components
If your application is developed for desktop, I'd recommend to use C++/Qt for desktop framework which will provide the native look and feel for your application. Although Qt Development Frameworks recently stated that their main strategy becomes Qt Quick while passing the commercial licenses and support to a company named Digia. So maybe it makes sense to think about whether its worth to use the desktop version of Qt or not.
Hope that helps
You can embed QWidgets and use them from QML. It takes a little C++ and isn't as nice as pure QML widgets, but it works pretty well and gives you access to a lot of existing Qt functionality.
You can use a QGraphicsWidget as explained (briefly) here. Alternatively you can do the reverse: embed a QML interface inside a Qt GUI, using QDeclarativeView as explained here.
Dan, thats a way to do that but: I'd say it is a way to "just do it" without any consideration of whether its right or wrong. Further, I'm not saying that your solution is wrong, I'm just trying to explain why I believe applications should not be implemented in that way.
First of all, as I mentioned, Qt Quick, as follows from its name, is designed to create user interfaces quickly. Trying to embed Qt desktop widgets in the graphics scene will create an additional effort (which might be quite big - depending on the task) of exporting the APIs to the QML environment and making everything work. Architecture of a QML application is very different from the desktop. If you work with model-view-controller for example, exporting QTreeView and QItemDelegate to the QML and making it work may turn to a very complicated solution. In fact, if follow that concept, the easiest way would be to create all the UI in C++ backend and export the final solution to QML but that in fact is a desktop implementation that doesn't take any advantages of QML at all. If do implementations in that way, its much easier to use Qt Animation API that would provide the same "fluid" effects that QML does but just using purely QGraphicsView.
Second, if you want to use existing desktop widgets in QGraphicsView you will have to embed them as "proxy widgets" which, according to Nokia guys who work on Qt Quick and QML has big problems with performance.
Third, if you want to use QGraphicsWidget approach, it will lead you to the implementation of all widgets from scratch because there are no QGraphicsWidget-based widgets in Qt. Even for something as simple as Push Button widget you will need to write all the code yourself.
Fourth, as Nokia stated previously, they handed off Qt desktop support to a 3rd party company explaining that they focus all their effort on Qt Quick. So I would think about the maintainability of your application. Plus with upcoming QML Scene Graph all QML API will be moved on that implementation and I'm not sure whether there will still be possible to use desktop widgets with it.
精彩评论