My situation: I have a grid layout with n*n widgets inside. Additionally I place an overlay widget in the grid with position 0,0 and span n,n.
Evertyhing fine with this, but there is a weird margin and I don't know what causes it...
Has anyone an idea how i can prevent this? I think I'm missing something trivial...
SudokuFieldWidget::SudokuFieldWidget(QWidget *parent) : QFrame(parent)
{
...
m_layout = new QGridLayout( this );
m_layout->setSpacing( 0 );
m_layout->setMargin( 1 );
this->initCells( true );
this->setLayout( m_layout );
m_markerOverlay = new SudokuMarkerOverlayWidget( this );
m_layout->addWidget( m_markerOverlay, 0, 0, m_fieldSize, m_fieldSize );
}
SudokuMarkerOverlayWidget::SudokuMarkerOverlayWidget(QWidget* parent) : QWidget(parent)
{
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_TransparentForMouseEvents);
...
}
void SudokuMarkerOverlayWidget::paintEvent(QPaintEvent*)
{
QPainter painter(this);
painter.fillRect( rect(), QColor( 255, 0, 0, 128 ) );
}
Had an error in my paint-Routine for SudokuFieldWidget which caused this misbehaviour...
m_markerOverlay->setGeometry( this->geometry() );