design - Custom Styling Qt Quick Controls -


i have custom design qt quick controls. example, change background colour of tool bar, since hate default design. how can that?

in qt quick controls, there limited styling available via qt quick control styles items, buttonstyle, checkboxstyle, etc.

at moment, other styles require delving qt sources , messing internal details.

here complete example of how 1 might modify toolbar's style.

screenshot

main.qml

import qtquick 2.1 import qtquick.layouts 1.0 import qtquick.controls 1.0  applicationwindow {     toolbar: toolbar {         id: toolbar         component.oncompleted: toolbar.data[0].item.children = [newrectangle];         property item _newrectangle: rectangle {             // rectangle within toolbarstyle's panel             // gleaned from:             // http://qt.gitorious.org/qt/qtquickcontrols/source/             //   c304d741a27b5822a35d1fb83f8f5e65719907ce:src/styles/base/toolbarstyle.qml             id: newrectangle             anchors.fill: parent             gradient: gradient{                 gradientstop{color: "#a00" ; position: 0}                 gradientstop{color: "#aaa" ; position: 1}             }             rectangle {                 anchors.bottom: parent.bottom                 width: parent.width                 height: 1                 color: "#999"             }         }         rowlayout {             toolbutton { iconsource: "image://images/img1" }             toolbutton { iconsource: "image://images/img2" }         }     } } 

main.cpp

#include <qguiapplication> #include <qqmlapplicationengine> #include <qquickwindow> #include <qimage> #include <qpainter> #include <qquickimageprovider> #include <qdebug>  class imageprovider : public qquickimageprovider { public:     imageprovider() : qquickimageprovider(qquickimageprovider::image) {}     qimage requestimage(const qstring &id, qsize *size, const qsize &requestedsize) {         qimage img(32, 32, qimage::format_argb32_premultiplied);         img.fill(0); // transparent         qpainter p(&img);         p.setrenderhint(qpainter::antialiasing);         p.translate(16, 16);         p.scale(14, 14);         p.setpen(qpen(qt::black, 0.1));         if (id == "img1") {             p.drawellipse(qpointf(0, 0), 1, 1);         }         else if (id == "img2") {             p.drawline(-1, -1, 1, 1);             p.drawline(-1, 1, 1, -1);         }         *size = img.size();         return img;     } };  int main(int argc, char *argv[]) {     qguiapplication app(argc, argv);     qqmlapplicationengine engine;     engine.addimageprovider("images", new imageprovider);     engine.load(qurl("qrc:///main.qml"));     qobject *toplevel = engine.rootobjects().value(0);     qquickwindow *window = qobject_cast<qquickwindow *>(toplevel);     window->show();     return app.exec(); } 

main.qrc

<rcc>     <qresource prefix="/">         <file>main.qml</file>     </qresource> </rcc> 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -