如何在Qt中创建一侧向内弯曲而另一侧平坦的QPushbutton

How to create a QPushbutton with one side curved inward and other side flat in Qt

QPushButton {    
    border: 2px solid red;
    height:24px;
    width:100px;
    border-top-left-radius: 50px;
    border-bottom-left-radius: 50px;
    border-top-right-radius: 0px;
    border-bottom-right-radius: 0px; 
}

这样我的一侧是圆的,另一侧是平的,就像这样

我希望一侧向内弯曲,另一侧平坦,就像平凹一样,有没有办法实现这个

我认为这里更好的方法是子类化 QPushButton and reimplement the paintEvent。像这样

void PushButton::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);

    // Define pen
    QPen pen;
    pen.setWidth(4);

    // Draw outer cover
    pen.setColor(Qt::black);
    painter.setPen(pen);
    painter.setBrush(QColor(Qt::gray));
    painter.drawRect(this->rect());

    // Draw Inward arc
    pen.setWidth(2);
    painter.setPen(pen);
    painter.setBrush(QColor(Qt::white));

    int x = this->rect().x() - this->rect().width()/2;
    int y = this->rect().y();
    int w = this->rect().width();
    int h = this->rect().height();
    QRectF rectangle(x,y,w,h);
    painter.drawRoundedRect(rectangle,w,h);

}

请记住,这只是一个示例,您应该考虑其他因素,例如小部件的大小和向内弯曲的角度等等。