Drawing Frames arround Widgets
-
@sandro4912
Hi
Looking good. :)The space can most likely be removed with
layout->setContentsMargins(0,0,0,0);
all layout have a default values of 9 for all 4 sides
-
Appling the margin i get this:
This is almost perfect. Just one nitpick.
The Top and Bottom frame seem to touch each other without any spae inbetween. Any change to add a space like between the outside frame and the inside frames?
The code now looks like this:
auto topLayout = new QHBoxLayout; topLayout->setSpacing(0); topLayout->setContentsMargins(0,0,0,0); topLayout->addWidget(mLcdDisplayMinesLeft); topLayout->addWidget(mSmileyPushButton); topLayout->addWidget(mLcdDisplayElapsedTime); mTopFrame->setLayout(topLayout); auto bottomLayout = new QHBoxLayout; bottomLayout->setSpacing(0); bottomLayout->setContentsMargins(0,0,0,0); bottomLayout->addWidget(mMinefield); mBottomFrame->setLayout(bottomLayout); auto mainLayout = new QVBoxLayout; mainLayout->setSpacing(0); mainLayout->addWidget(mTopFrame); mainLayout->addWidget(mBottomFrame); mMainFrame->setLayout(mainLayout); auto layout = new QVBoxLayout; layout->setSpacing(0); layout->setContentsMargins(0,0,0,0); layout->addWidget(mMainFrame); setLayout(layout);
-
I could solve the Issue by removing the Space 0 here:
auto mainLayout = new QVBoxLayout; //mainLayout->setSpacing(0); mainLayout->addWidget(mTopFrame); mainLayout->addWidget(mBottomFrame);
Which gives:
That looks pretty close to the original:
Although it looks like there is still some kind of space between the minefield and the frame? Can it be removed aswell?
-
Hi
It looks very much like the original
How nostalgic :) -
Yes the only Issue I still see is the remainig space between minefield and the bottomFrame.
-
Hi
There ?
-
Yes in the original theres no space at all.
I already throw out the top frame for testing to see if it causes it but still same result.
-
@sandro4912
Hi
Im not sure where that space comes from as it seems you have it to zeroauto bottomLayout = new QHBoxLayout;
bottomLayout->setSpacing(0);
bottomLayout->setContentsMargins(0,0,0,0);
bottomLayout->addWidget(mMinefield);
mBottomFrame->setLayout(bottomLayout);Did you try to raise the margins to see if you then get more space there ?
-
This post is deleted!
-
hi @sandro4912 ,
my guess is, that the margins come from the mainLayout. You only set the
setContentsMargins
to 0 inside the bottomLayout, but the insert that layout into the mainLayout which has its own contentMargins still != 0 -
No it still has the same Issue:
auto topLayout = new QHBoxLayout; topLayout->setSpacing(0); topLayout->setContentsMargins(0,0,0,0); topLayout->addWidget(mLcdDisplayMinesLeft); topLayout->addWidget(mSmileyPushButton); topLayout->addWidget(mLcdDisplayElapsedTime); mTopFrame->setLayout(topLayout); auto bottomLayout = new QHBoxLayout; bottomLayout->setSpacing(0); bottomLayout->setContentsMargins(0,0,0,0); bottomLayout->addWidget(mMinefield); mBottomFrame->setLayout(bottomLayout); auto mainLayout = new QVBoxLayout; mainLayout->setSpacing(0); mainLayout->setContentsMargins(0,0,0,0); mainLayout->addWidget(mTopFrame); mainLayout->addWidget(mBottomFrame); mMainFrame->setLayout(mainLayout); auto layout = new QVBoxLayout; layout->setSpacing(0); layout->setContentsMargins(0,0,0,0); layout->addWidget(mMainFrame); setLayout(layout);
Result:
-
@sandro4912
mmh, strange.I'm out of easy ideas to try 😞
sry -
Hi
What about INSIDE minefield ?
Did you use layout there ? -
Yes inside the Minfield I place the Cells like this in the constructor:
auto layout = new QGridLayout; layout->setSpacing(0); for(int i = 0; i < mCells.size(); ++i) { auto column = static_cast<int>(i % mFieldWidth); auto row = static_cast<int>(i / mFieldWidth); layout->addWidget(mCells[i], row, column); } setLayout(layout);
-
But you dont seem to call setContentsMargins(0,0,0,0);
so maybe that is the space ? -
@mrjj said in Drawing Frames arround Widgets:
setContentsMargins(0,0,0,0);
thats it!
I thought i tryed it before but i think i tryed:
setContentsMargins(0,0,0,0);
and not
layout->setContentsMargins(0,0,0,0);