ivoflipse / Pawlabeling

Tool for processing and analyzing pressure measurements
Other
18 stars 1 forks source link

Make widgets scale dynamically scale with the whole application window #21

Closed ivoflipse closed 11 years ago

ivoflipse commented 11 years ago

I've looked into this before and couldn't get it working properly, due to interpolation issues. But I should try to make the widgets (and the content they display) scale dynamically with the size of the application window.

ivoflipse commented 11 years ago

I'm trying to see if I can resize the entire plate widget when you resize the window, but I think I should just be scaling the graphicsview, not the actual image its drawing

ivoflipse commented 11 years ago

I wrote a piece of code, based on: http://stackoverflow.com/questions/5637772/zoom-qgraphicsitem-to-fit-qgraphicsview

def resizeEvent(self, event):
    item_size = self.view.mapFromScene(self.image.sceneBoundingRect()).boundingRect().size()
    ratio = min(self.view.viewport().width()/float(item_size.width()),
                self.view.viewport().height()/float(item_size.height()))

    if abs(1-ratio) > 0.1:
        self.image.setTransform(QtGui.QTransform.fromScale(ratio, ratio), True)
        for item in self.bounding_boxes:
            item.setTransform(QtGui.QTransform.fromScale(ratio, ratio), True)
        for item in self.gait_lines:
            item.setTransform(QtGui.QTransform.fromScale(ratio, ratio), True)
        #self.view.fitInView(self.rect(), Qt.KeepAspectRatio)
        self.view.centerOn(self.image)

However, it only updates when I resize the window. So if I update in between, the bounding boxes get redrawn and they no longer match the resized self.image. I need to come up with a way that's a bit more generic.

Also, for some reason, even if the image fits the screen nicely, the view or scene seems to grow, so you get scroll bars

ivoflipse commented 11 years ago

I added a variable that stores (and keeps up to date) the ratio with which the view is resized and updates the polygons/lines when they are drawn.

I also make sure the scene's rect gets updated, so we shouldn't see too many scrollbars.

ivoflipse commented 11 years ago

I forgot that the force/pressure graphs probably would like to scale as well, at least a little bit. Apparently you can use: fig.set_size_inches(w, h) (see http://matplotlib.org/api/figure_api.html)

ivoflipse commented 11 years ago

And there's an issue with the results, because they don't get updated if they're not visible. Which means the 'miss' any intermediate changes to the ratio, so they sort of go out of sync along the way. Perhaps there's a more reliable way of calculating the ratio, that also keeps track of the widget that contains the view.

ivoflipse commented 11 years ago

The COP widget seems to behave right now, but still not entirely satisfied

ivoflipse commented 11 years ago

The reason the force/pressure graphs weren't scaling is because I had added a stretch to the layout, removing that, they simply scaled to the size of their widget. Looks good!