问题
I want to add a top right button for closing a widget that floats over others. I can´t make it float out of the contents of the panel.

I tried several ways. Having the background normally doesn´t work. I cant make a widget float outside the box inside that background.
It was done this way:
border-style: solid;
border-width: 12px 24px 37px 25px;
border-image: url(:/resources/images/panel_border_corner_btn.png) 12 24 37 25 fill repeat;
margin: 0px;
padding: 0px;
So i tried to make a background with 10 px on the top and right sides transparents, like this (you won´t see the transparent zones, but if you download it, you will see it).

so i add the widget with the button background:

But i can´t make it overflow the border anyways. Modifying the margin with -20 cuts it, using padding -20 doesn´t work...
回答1:
Here's my example:
FloatPanel::FloatPanel(QWidget *parent) :
QWidget(parent)
{
setAutoFillBackground(true);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(5, 15, 15, 5);
layout->addWidget(new QLabel("some text"));
layout->addWidget(new QPushButton("some button"));
}
void
FloatPanel::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter(this);
painter.setPen(Qt::black);
painter.setBrush(Qt::white);
painter.drawRect(0, 10, width() - 12, height() - 11);
painter.drawPixmap(width() - 38, 0, QPixmap(":/close.png"));
}
And this is the result:

来源:https://stackoverflow.com/questions/17166670/qt-border-transparency-and-padding-how-to-create-this-effect