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