How do I overlay widgets in Qt?
I want to create some widgets and place them out-of-layout, but rather tweak their size and position when some other widget's geometry is changed.
Something like the buttons on the screenshot:
How do I overlay widgets in Qt?
I want to create some widgets and place them out-of-layout, but rather tweak their size and position when some other widget's geometry is changed.
Something like the buttons on the screenshot:
QPushButton (または任意の QWidget) を作成し、その親 QWidget を指定して表示するだけです。
親レイアウトに追加しないでください。そうしないと、必要に応じて移動できなくなります。
その親を示すことを忘れないでください。そうしないと、独立した QWidget として表示されます。
これらの条件では、QPushButton は QWidget の子と見なされますが、親のレイアウトのメンバーではありません。したがって、それは「フローティング」の子になり、親の QWidget のサイズを変更するときにその動作を管理する必要があります。
すべてのオーバーレイ ボタンに統一された動作が必要な場合は、QLayout
メンバーの動作をサブクラス化して再定義する必要があります。
If they're child of a widget without a layout, you should be able to move them around as you please, I think.
私が取り組んでいるプロジェクトにはこのようなウィジェットが必要だったので、Patrice のアドバイスを受けてこのコードを書きました (Python) PyQt4 Widget Overlay