【问题标题】:Qt customize the rectangle boundaries to get mild 3D effectQt自定义矩形边界以获得温和的3D效果
【发布时间】:2013-03-17 07:45:28
【问题描述】:

您能否告诉我如何通过自定义 QGraphicsItem 绘制带有this 等边界的矩形。我做了布局并绘制了矩形,但我的rectangles 的边界是普通的笔。请求您的帮助。谢谢。

void QGraphicsTileItem::paint(QPainter *painter,
                              const QStyleOptionGraphicsItem *option,
                              QWidget *widget)
{
    /// Draw the rect
    painter->setRenderHints( QPainter::Antialiasing |
                             QPainter::TextAntialiasing |
                             QPainter::SmoothPixmapTransform |
                             QPainter::HighQualityAntialiasing, true );
    painter->setPen( pen );
    painter->setBrush( colour );
    painter->drawRect( bound );
    painter->drawText( bound, Qt::AlignLeft | Qt::AlignTop |
                       Qt::TextSingleLine, name );
}

【问题讨论】:

  • 我不会画矩形。我会画 2 组线。
  • 照@Sosukodo 所说的去做。

标签: qt qt4 qt5


【解决方案1】:

这是一个来自 QWidget 的paintEvent 示例。您应该能够使其适应您的绘画事件(您将使用绑定变量而不是“this”):

void Button::paintEvent(QPaintEvent *e)
{
    QPainter paint;
    paint.begin(this);
    paint.setPen(Qt::white);
    paint.drawLine(0,0, this->width(), 0);
    paint.drawLine(0,0, 0, this->height());
    paint.setPen(Qt::black);
    paint.drawLine(0, this->height()-1, this->width()-1, this->height()-1);
    paint.drawLine(this->width()-1, 0, this->width()-1, this->height()-1);
    paint.end();
}

【讨论】:

  • [This][1] 是我现在得到的,谢谢。但这并不是我想要达到的目标。请有任何建议。 [1]picasaweb.google.com/lh/photo/…
  • 这个解决方案只需稍加调整即可正常工作。非常感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-12-04
  • 2021-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-25
  • 2012-11-19
相关资源
最近更新 更多