cdr如何設(shè)置選邊框只能選擇邊線

在C++中使用Qt框架時,如果你想設(shè)置一個邊框只顯示邊線而不顯示填充色,可以通過設(shè)置`QGraphicsItem`的`pen`屬性來實現(xiàn)。以下是一個簡單的例子,展示了如...
在C++中使用Qt框架時,如果你想設(shè)置一個邊框只顯示邊線而不顯示填充色,可以通過設(shè)置`QGraphicsItem`的`pen`屬性來實現(xiàn)。以下是一個簡單的例子,展示了如何設(shè)置一個`QGraphicsRectItem`的邊框只顯示邊線:
```cpp
include
include
include
include
include
int main(int argc, char argv[])
{
QApplication a(argc, argv);
QGraphicsScene scene;
QGraphicsView view(&scene);
view.setRenderHint(QPainter::Antialiasing);
view.setGeometry(100, 100, 400, 300);
view.show();
QGraphicsRectItem rectItem = new QGraphicsRectItem(50, 50, 100, 100);
scene.addItem(rectItem);
// 設(shè)置邊框樣式,只顯示邊線,不顯示填充色
QPen pen;
pen.setColor(Qt::black); // 設(shè)置邊框顏色
pen.setWidth(2); // 設(shè)置邊框?qū)挾?
pen.setStyle(Qt::SolidLine); // 設(shè)置邊框樣式為實線
rectItem->setPen(pen); // 應(yīng)用邊框樣式到矩形項
return a.exec();
本文鏈接:http:///bian/373216.html
上一篇:陜鐵院是大專還是高職