qt - Displaying image as background of QGraphicsScene -


i try use qgraphicsview display map qgraphicitem-subclass showing region centers of map. conceptually, organize map follow:

qgraphicsview   qgraphicsscene     qgraphicspixmapitem  : background image, fixed until next call of loadsetting     qgraphicsrectitem    : legend, position relative bg fixed throughout app     qgraphicsellipseitem : region centers 

i want map behave follow:

  • no scrollbars displayed, , background image fillup visible area of view/scene.
  • when widget re-sized, qgraphics*items re-size accordingly (as if view zoomed)
  • relative positions of qgraphicsellipseitems, remain fixed until next call of loadsetting()

    now have problem in getting background image displayed properly.

constructor [i'm adding view qtabwidget directly: mytab->addtab("name", my_view_); ]

myview::myview(qwidget *parent) : qgraphicsview(parent) {     bg_pixmap_ = new qgraphicspixmapitem();     legend_    = new maplegend();     setscene(new qgraphicsscene(this));     scene()->additem(bg_pixmap_);     scene()->additem(legend_); } 

load map setting (during program execution, method may invoked multiple times)

void myview::loadsetting(config* cfg) {     if (!cfg) return;      /* (a) */     scene()->clearfocus();     scene()->clearselection();     (int = 0; < symbols_.size(); i++)         scene()->removeitem(symbols_[i]);     qdeleteall(symbols_);     symbols_.clear();     /* (a) */      /* (b) */     background_ = qpixmap(qstring::fromstdstring(cfg->district_map));     bg_pixmap_->setpixmap(background_);     (size_t = 0; < cfg->centers.size(); i++) {         qreal x = cfg->centers[i].first * background_.width();         qreal y = cfg->centers[i].second * background_.height();         mapsymbol* item = new mapsymbol(x, y, 10);         symbols_.append(item);         scene()->additem(item);     }     /* (b) */     update(); } 

questions

  • now items except 'bg_pixmap_' got displayed, , checked 'background_' variable loads image correctly. there missed?

  • how implement resizeevent of myview cope desired 'resize-strategy'?


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -