Hi, Dawid.
Dawid Sip wrote:
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?
The graphics view has the possibility of setting any transform/matrix on
it to alter how and which part of the scene is displayed. For your
particular case there is also a convenience method which sets the
correct scale on the view so that a specific item fits perfectly inside it.
http://doc.trolltech.com/qtjambi-4.4.0_01/doc/html/com/trolltech/qt/gui/QGraphicsView.html#fitInView(com.trolltech.qt.gui.QGraphicsItemInterface)
I have attached a modification to the previous example of how you can
use this method to achieve what you need. Please make sure you set the
scrollbar policy of the view to no scrollbars in both vertical and
horizontal direction, though, otherwise you will get an infinite stream
of resize events as the scrollbars automatically switch on and off.
Hope this helps.
-- Eskil
import com.trolltech.qt.core.Qt;
import com.trolltech.qt.core.Qt.Orientation;
import com.trolltech.qt.gui.*;
class MyDockWidget extends QDockWidget {
private static QPixmap pixmap = new QPixmap("classpath:com/trolltech/images/qt-logo.png");
int i=0;
public MyDockWidget() {
QGraphicsScene scene = new QGraphicsScene();
final QGraphicsPixmapItem item = scene.addPixmap(pixmap);
QGraphicsView view = new QGraphicsView() {
@Override
protected void resizeEvent(QResizeEvent e) {
fitInView(item);
super.resizeEvent(e);
}
};
view.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff);
view.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff);
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