I have a custom widget derived from QWidget
, which has a minimumSize
of (30, 30)
and a QLabel
as a childWidget
:
MyWidget::MyWidget (QWidget *parent, QPoint p,
QWidget *childWidget) : QWidget (parent)
{
childWidget = this->childWidget;
setAttribute (Qt::WA_DeleteOnClose);
this->move (p);
verticalLayout = new QVBoxLayout (this);
if (childWidget != NULL)
{
childWidget->setParent (this);
childWidget->releaseMouse();
childWidget->setAttribute (Qt::WA_TransparentForMouseEvents, true);
verticalLayout->addWidget (childWidget);
}
this->setLayout(verticalLayout);
};
MyWidget::mouseMoveEvent (QMouseEvent *e)
{
if (! (e->button() == Qt::RightButton))
{
this->update();
this->raise();
}
}
void MyWidget::mouseReleaseEvent (QMouseEvent *evt)
{
QWidget::mouseReleaseEvent(evt);
this->update();
}
MyWidget::mousePressEvent (QMouseEvent *e)
{
if (! (e->button() == Qt::RightButton))
{
this->update();
this->raise();
}
}
void MyWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::darkGreen);
painter.drawRect(1, 2, 6, 4);
painter.setPen(Qt::darkGray);
painter.drawLine(2, 8, 6, 2);
}
//And some getter/setter methods.
In order to set a border to the widget I use the following code:
customWidget->setStyleSheet("*{border-width:" +
2 +
";border-style:solid;border-color:" +
#FFFFFF + " ;color:white;}");
It looks like this (the parent widget has an orange background):
When I change the border-width
to 10, the border covers the contents:
Both images show the widget in its minimum height.
To me it looks as if the border were applied inwards. What shall I modify to point the border outwards, so for a larger border-width
the text remains visible?