【发布时间】:2016-03-11 12:52:42
【问题描述】:
我希望我的GraphicsView的边框与这张图片完全一样。
我从QGraphicsView 继承了一个类,并尝试在drawBackground 和paintEvent 中绘制此图像,但它们都不起作用。
我的代码:
.h 文件
class GraphicsTraxSuggestionView : public QGraphicsView {
Q_OBJECT
public:
GraphicsTraxSuggestionView(QWidget* widget);
protected:
// void paintEvent(QPaintEvent *event);
void drawBackground(QPainter *p, const QRectF &rect);
private:
};
.cpp 文件
GraphicsTraxSuggestionView::GraphicsTraxSuggestionView(QWidget* widget)
: QGraphicsView(widget)
{
//setFrameShadow(QFrame::Raised);
setFrameStyle(QFrame::NoFrame);
setStyleSheet("QGraphicsView { border-style: none; }");
}
void GraphicsTraxSuggestionView::drawBackground(QPainter *painter, const QRectF &rect)
{
painter->drawImage(rect, QImage("suggestionBorder.png"));
}
我的代码结果:http://i.stack.imgur.com/r0waP.png
有什么建议吗?
【问题讨论】:
-
您能否在问题中添加您不工作的
drawBackground实现? -
如何设置 GW 的大小?你能登录
rect和QImage("suggestionBorder.png").rect()吗? -
@Ilya 我希望视图形成图像的形状。我不知道你为什么认为尺寸很重要?
-
反之亦然,图像可以拉伸以适应视图,但您必须设置视图大小。
标签: c++ qt border qgraphicsview