Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating "pretty" Qt Custom Widgets

Tags:

What is the process behind making custom widgets (using Qt) that don't look...well...ugly?

I know it is fairly trivial to make a "custom widget" that has say, a listbox and a pushbutton slapped together into one, but how would I go about making something that looks more like this:

QAnalogWidgets

I have made some rough mock-ups that basically use a PNG background (that I made in Photoshop) with basic elements like QLabels placed on top of them, but I don't think this is how I should be doing it. I know that Qt supports CSS -- is this what people use to create widgets that actually look good? Do I need to be working in the paintEvent methods? OpenGL?

Trying to search for anything "custom widget qt" related is just giving me tons of info about how to import them into the Designer, etc -- so any leads would be appreciated.

Thanks!

like image 810
swanson Avatar asked Oct 05 '09 21:10

swanson


People also ask

How do I create a custom widget in Qt?

Adding the Custom Widget to Qt Designer. Click Tools|Custom|Edit Custom Widgets to invoke the Edit Custom Widgets dialog. Click New Widget so that we are ready to add our new widget. Change the Class name from 'MyCustomWidget' to 'Vcr'.

Should I use Qt Quick or Qt widgets?

Qt Widgets provide means for customization via style sheets, but Qt Quick is a better performing choice for user interfaces that do not aim to look native. Qt Widgets do not scale well for animations. Qt Quick offers a convenient and natural way to implement animations in a declarative manner.


2 Answers

There's basically three different things to try, in the order listed:

  1. CSS / stylesheets. Stylesheets, when sufficiently powerful for your needs, are great and allow for runtime style changes. See the stylesheet examples.
  2. Custom painting. You can do virtually anything you want with custom painting. Qt's support for PNGs and SVGs should help a lot. You'll want to take a look at the painting examples. Also, take a look at the QStyle documentation to understand what kinds of style information you should consider.
  3. Custom styles. If you need to customize the whole application, you might be better off creating your own style. Not for the faint of heart.

Basically, go with the easiest possible solution that will work for you. Also, take a look at Qt Creator, it's nicely styled and all the source code is available.

like image 94
Kaleb Pederson Avatar answered Sep 30 '22 13:09

Kaleb Pederson


Here is a tutorial to create custom Window by removing System top bar and drawing the bacground : http://qt.developpez.com/tutoriels/braindeadbzh/customwindow/.

Since he is sub-classing a QWidget, you can do this for all QWidget subclass like QPushButton).

When You want to use them in QTDesigner, just include your class and then promote a "classic" widget to your custom one. This can be helpful: http://pepper.troll.no/s60prereleases/doc/designer-using-custom-widgets.html.

like image 32
Patrice Bernassola Avatar answered Sep 30 '22 13:09

Patrice Bernassola