You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, May 24th 2012, 8:30am

Two question about QGraphicsView , Thanks

1:Why I have to call
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff) to disable
scrollbar, otherwise they will show even the view equal scene.
2:After call fitInView in resizeEvent, there is always a margin in view. what should I do?

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent), 
ui(new Ui::MainWindow),myView(new View) 
{ 
ui->setupUi(this); 

this->myView->setFixedSize(400, 300); 

this->setCentralWidget(this->myView); 

this->myScene = new QGraphicsScene; 

this->myScene->setSceneRect(this->myView->rect()); 

this->myView->setScene(this->myScene); 
//why I have to call these function to diable scrollbar,otherwise they will show no matter the view and scene size 
this->myView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 
this->myView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 

} 

MainWindow::~MainWindow() 
{ 
delete ui; 
} 
void MainWindow::on_actionAdd_triggered() 
{ 
QGraphicsTextItem *pitem = new QGraphicsTextItem("new Text"); 

pitem->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable); 

this->myScene->addItem(pitem); 
} 

void MainWindow::on_actionClear_triggered() 
{ 
this->myScene->clear(); 
} 

void MainWindow::on_actionZoomin_triggered() 
{ 
this->myView->adjustSize(); 
} 

void MainWindow::resizeEvent(QResizeEvent *event) 
{ 
//if I call this fitInView, there will be a margin in view. why 
this->myView->fitInView(0,0,400,300,Qt::KeepAspectRatio); 

}
henryxuv has attached the following file:
  • test.zip (6.32 kB - 2 times downloaded - latest: Nov 2nd 2012, 7:57pm)

This post has been edited 1 times, last edit by "henryxuv" (May 25th 2012, 2:20am) with the following reason: nobody reply