Hi,
the solution with the overriden resizeEvent of the GraphicsView was a nice learning example but unfortunately it is not exactly what I'am looking for. I want the scene (or Pixmap) to fit into the GraphicsView but I dont want to rescale it and loose data. Thus, what I need is to somehow rescale the scene in which the pixmap resolution stays untougched. For example, I work with large images (~2500x2000) and I want to show them in graphicsView which is ~400x300, scaled so the image fits into that 300x400 view and the image resolution stays 2500x2000(inside pixmap item) and when I click in the middle of that GraphicsView -pos(150,200) I can transform this down to the item and get somethink like pos(1250x1000). So I somehow need to adjust the projection. I think this is an issue of the viewport. I think I could achieve this by changing the viewport to QGLWidget and with help of some wrapper lib. like JOGL adjust the viewport/frustum, but I'd rather not use OpenGL in my application. So is this the only way or can I still do this with the default QWidget as viewport?

Sow the question is: "How to show large pixmpa in a small viewport without loosing pixmap data"

Could somebody please point me in the right direction?

Dawid
Dawid Sip wrote:
I understand that the resizeEvent is propageted like this:
MainWindow
    ->Splitter
       -->dockWidget
          --->GraphicsView
             ---->GraphicsScene
                ----->Image

So my guess is that I have to reimplement resizeEvent of the GraphicsScene, where i can get the size of the parent - GraphicsView and with this size i can set the size of the Image?

The size of graphics scene is not really related as the view can view any part of the scene you want. The layout system will make sure that the size of the view is connected to the size of the dock widget (which again is controlled by the splitter), so you would only need to listen to the resize event of the view and your application will work regardless of how the widget hierarchy looks. I've modified your example a little to show you how this might be done. Please note that this is probably not your most highly optimized example (you might want to turn off opaque resizing for the splitters to avoid big garbage collection steps and to increase the performance), but it shows you the idea. (Also, this won't work if you add any transform to the graphics view of course, in fact most of the things you can do with a graphics view will break it, but I wanted to recreate the hierarchy in your drawing above.)

Just replace the hard coded path of the icon to something you have available.

Hope this is what you were looking for!

-- Eskil


------------------------------------------------------------------------

import com.trolltech.qt.core.Qt.Orientation;
import com.trolltech.qt.gui.*;

class MyDockWidget extends QDockWidget {
        
        public MyDockWidget() {
                
                QGraphicsScene scene = new QGraphicsScene();    
                final QPixmap pixmap = new 
QPixmap("classpath:com/trolltech/images/qt-logo.png");
                final QGraphicsPixmapItem item = scene.addPixmap(pixmap);
                
                QGraphicsView view = new QGraphicsView() {
                        
                        @Override
                        protected void resizeEvent(QResizeEvent e) {
                                item.setPixmap(pixmap.scaled(e.size()));
                                super.resizeEvent(e);
                        }                       
                };
                view.setScene(scene);

                setWidget(view);                
        }
        
}

public class guiSplit extends QMainWindow{

    Ui_guiSplitClass ui = new Ui_guiSplitClass();
    QSplitter spliterV = new QSplitter(Orientation.Vertical);
    QSplitter spliterH = new QSplitter(Orientation.Horizontal);
    private int imageInCentralWidget = 0;
public static void main(String[] args) {
        QApplication.initialize(args);
        guiSplit testguiSplit = new guiSplit();
        testguiSplit.show();
        QApplication.exec();
    }
public guiSplit(){
        ui.setupUi(this);
spliterV.addWidget(spliterH); QWidget w = new QWidget(); QHBoxLayout layout = new QHBoxLayout(w);
        layout.addWidget(spliterV);
setCentralWidget(w);
    }
public guiSplit(QWidget parent){
        super(parent);
        ui.setupUi(this);
    }
QDockWidget dockWid;
    public void on_actionAddDockWid_triggered() {
        if(imageInCentralWidget==3) return;
        
        System.err.println("\n\n\n");
        dockWid = new MyDockWidget();
        dockWid.setObjectName("dockWid"+(++imageInCentralWidget));
        
dockWid.setFeatures(com.trolltech.qt.gui.QDockWidget.DockWidgetFeature.createQFlags(com.trolltech.qt.gui.QDockWidget.DockWidgetFeature.NoDockWidgetFeatures));
QApplication.processEvents(); switch(imageInCentralWidget){
                case 1:
                        spliterH.addWidget(dockWid);
                        break;
                case 2:
                        spliterH.addWidget(dockWid);
                        break;
                case 3:
                        spliterV.addWidget(dockWid);
                        break;
} }
}

_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest

Reply via email to