1

私は Qt アプリケーションにしばらく取り組んでおり、多くのコードを書き直した後、GUI を改良したいと考えました。そこで、GUI のデザインを調べていて、ほとんどの場合、ネイティブ ボタン/スクロール バーなどの代わりに画像が使用されていることに気付きました。

私の主な質問は、プッシュ ボタンなどのネイティブ ウィジェットを使用して、プッシュ ボタンのすべての機能 (アニメーション クリック、シグナル、スロットなど) を備えたプッシュ ボタンのイメージを表示する方法です。これを行う QML やその他の方法を見てきましたが、通常の C++ と Qt を使用してこれを行う方法は見つかりませんでした。

4

1 に答える 1

0

The simplest way is to use the palette and/or stylesheets to get the appearance you want, or at least close to what you want. That is the way I'd recommend for most uses, honestly.

For buttons, you can do something by inhering from QAbstractButton and having your own images you draw for all the various states. You'd need to figure out the states you want to support, and when to draw them (look at the options passed to paintEvent, for example). This is a little more difficult, but code-wise is fairly simple. Your main problems with this option are generating the images, and that the result is fragile for resizing -- that is, basically, don't allow those buttons to resize. The other drawback is that you would have to do something similar for every widget you want to style, and many of them aren't nearly as simple as buttons.

To go all the way, you can look at QStyle, and how the various styles are implemented. Using those, you can really make any widget appear just how you want it to appear (within the constraints of the size it is drawn in). This is the hardest option by far to understand what to do, and what the options are. Also, the last time I looked, many of the options aren't incredibly well documented for what they do in specific cases, so when I had to make some changes this way it was very much a matter of trial and error.

于 2012-09-19T16:03:21.200 に答える