我希望我的 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
有什么建议吗?
最佳答案
1) 创建一个QGraphicsScene
有你的图片大小
2) 将其设置为 View 的场景
3) 像现在一样在drawBackground
中绘制
关于c++ - QGraphicsView 周围的自定义边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35940783/