1:Why I have to call
setHorizontalScrollBarPolicy(Qt:

crollBarAlwaysOff) 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);
}
|