假设我想在某个 场景图 一个简单的家谱树。那里的每个人都正好有一个名字和一个姓氏(没有其他显示)。
对于那里的每个人,我想建立一个 QGraphicsItemGroup 由两个 QGraphicsSimpleTextItem -s vertically aligned and centered. One for first names of persons, one for their family names. Each having its own font & color. I don't want to use a heavy 绘图文本项目(QGraphicsTextItem 因为它太沉重了(一个只有姓和名的人名不值得一个完整的 QTextDocument ).
所以我在想
struct Person {
QGraphicsItemGroup _group;
QGraphicsLinearLayout _lay;
QGraphicsSimpleTextItem _firstname;
QGraphicsSimpleTextItem _lastname;
public:
Person(QGraphicsScene*scene,
const std::string& first, const std::string& last)
: group(), _lay(Qt::Vertical),
_firstname(first.c_str()), _lastname(last.c_str()) {
_lay.addItem(&_firstname);
_lay.setSpacing(0, 5);
_lay.addItem(&_lastname);
_group.addToGroup(&_firstname);
_group.addToGroup(&_lastname);
scene->addItem(&_group);
但这不起作用,因为_lay.addItem(&_firstname);不能编译,因为一个QGraphicsSimpleTextItem不是一个QGraphicsLayoutItem。
有什么提示吗?或者我的整个方法是错误的?
我是否应该定义一个既继承于QGraphicsSimpleTextItem又继承于QGraphicsLayoutItem的类?
注:实际代码(GPlv3许可)在我的玄武门 project on github, file guiqt.cc, commit 99fd6d7c1ff261.这不是一个家谱项目,而是一个抽象的语法树编辑器,类似于一个具有持久性的解释器的东西。所关注的类是BxoCommentedObjrefShow;我显示的不是名字,而是像_7rH2hUnmW63o78UGC这样的id,而不是姓氏,我显示的是像body of test1_ptrb_get这样的简短评论。在这里,我想说的是玄武门该项目本身是一个暂定的重写项目。melt-monitor-2015 in C++11 & Qt5