2016-07-22 2 views
0

QGraphicsScene 안에 QGraphicsWidgetQGraphics[Linear]Layout을 사용하여 '위젯'과 같은 노드를 만듭니다. 각 노드에는 헤더, 복수 IOGraphicsWidgets 및 바닥 글이 있습니다.QGraphicsWidget 및 QGraphicsLayout 간격 및 크기

코드 구조 :

Code structure

레이아웃을 원 :

Node layout

현재 코드의 결과 :

Current result

보시다시피 NodeGraphicsWidget (HeaderWidget 뒤의 빨간색 사각형)은 추가 된 모든 항목을 포함하도록 크기가 조정되지 않습니다. LayoutItems 사이의 간격도 매우 커서 m_centerWidgetLayout->setSpacing(0)은 변경되지 않았습니다. 지금은 모든 레이아웃을 직접 작성하려고 생각하고 있지만 표준 Qt를 사용할 수있는 더 좋은 방법이 있기를 바랍니다.

NodeGraphicsWidget:addIOWidget(AbstractIOGraphicsWidget *ioWidget)m_centerWidgetLayout에 주어진 AbstractIOGraphicsWidget을 그냥 추가합니다. NodeGraphicsWidget

생성자 : https://github.com/nidomiro/QtNodes/tree/f5426c154a4938481f00031f031507499cc0e183/src

답변

0

내가 내 문제 나 자신에 대한 해결책을 발견 :

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); 

} 

전체 소스 코드의 방문을 볼 수 있습니다. 처음에는 NodeGraphicsWidget이라는 루트 레이아웃을 잊어 버렸지 만 전체적인 문제는 해결되지 않았습니다. 주요 쟁점, 항목 사이의 간격은 실제 문제가 아니 었습니다. 진짜 문제는 모든 QGraphicsLinearLayout에는 기본적으로 여백이 있고 AbstractIOGraphicsWidget root-layout에는 그 여백이 있다는 것이 었습니다. layout->setContentsMargins(0,0,0,0)이 문제를 해결했습니다.