QGraphicsScene
の中にQGraphicsWidget
とQGraphics[Linear]Layout
を使用して、「ウィジェット」のようなノードを作成します。 各ノードにはヘッダーがあり、複数のIOGraphicsWidgets
とフッターがあります。QGraphicsWidgetとQGraphicsLayoutの間隔とサイズ
コード構造:
所望レイアウト:
現在のコードの結果:
あなたが見ることができるように、NodeGraphicsWidget
(HeaderWidgetの背後にある赤い矩形)は、追加されたすべてのアイテムを含むようにサイズ変更されません。 LayoutItems
の間隔も大きく、m_centerWidgetLayout->setSpacing(0)
は何も変更されていません。今、私は自分自身ですべてのレイアウトを書くことを考えていますが、私は標準的なQtを使うことができるより良い方法があることを願っています。
NodeGraphicsWidget:addIOWidget(AbstractIOGraphicsWidget *ioWidget)
は、m_centerWidgetLayout
に指定されたAbstractIOGraphicsWidget
を追加するだけです。
NodeGraphicsWidget
のコンストラクタ:
NodeGraphicsWidget::NodeGraphicsWidget(NodeGraphicsWidget::WidgetCreationFunction headerCreationFunc, NodeGraphicsWidget::WidgetCreationFunction footerCreationFunc, QGraphicsItem *parent, Qt::WindowFlags wFlags):
QGraphicsWidget(parent, wFlags)
{
m_headerWidget = new QGraphicsWidget(this);
m_centerWidget = new QGraphicsWidget(this);
m_centerWidgetLayout = new QGraphicsLinearLayout(Qt::Orientation::Vertical, m_centerWidget);
m_centerWidgetLayout->setSpacing(0);
m_centerWidget->setLayout(m_centerWidgetLayout);
m_footerWidget = new QGraphicsWidget(this);
headerCreationFunc(this, m_headerWidget);
if(footerCreationFunc != nullptr){
footerCreationFunc(this, m_footerWidget);
}
setAutoFillBackground(true);
QPalette pal;
pal.setColor(QPalette::Window, QColor(Qt::red));
this->setPalette(pal);
}
フルソースコードの訪問を参照するには、次のhttps://github.com/nidomiro/QtNodes/tree/f5426c154a4938481f00031f031507499cc0e183/src