Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
soitool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bachelor-paa-bittet
soitool
Commits
e29c068c
Commit
e29c068c
authored
5 years ago
by
Thomas Holene Løkkeborg
Browse files
Options
Downloads
Patches
Plain Diff
#18 ViewArea nå GraphicsScene + zoom
WIP
parent
a66272b6
No related branches found
No related tags found
1 merge request
!3
#18 MVP brukergrensesnitt - inline edit view
Pipeline
#70959
passed
5 years ago
Stage: lint
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
soitool/main_window.py
+62
-6
62 additions, 6 deletions
soitool/main_window.py
with
62 additions
and
6 deletions
soitool/main_window.py
+
62
−
6
View file @
e29c068c
"""
Hovedvinduet.
"""
"""
Hovedvinduet.
"""
import
sys
import
sys
import
os
import
os
from
PySide2.QtWidgets
import
QTabWidget
,
QWidget
,
QMainWindow
,
\
from
PySide2.QtCore
import
QRectF
,
QPoint
,
QTimer
QApplication
,
QHBoxLayout
,
QVBoxLayout
,
QPushButton
,
QTreeWidget
,
QLabel
from
PySide2.QtWidgets
import
QTabWidget
,
QWidget
,
QMainWindow
,
QApplication
,
\
QHBoxLayout
,
QVBoxLayout
,
QPushButton
,
QTreeWidget
,
QGraphicsScene
,
\
QGraphicsView
from
PySide2
import
QtGui
from
PySide2
import
QtGui
...
@@ -72,12 +74,66 @@ class MainWidget(QWidget):
...
@@ -72,12 +74,66 @@ class MainWidget(QWidget):
class
ViewArea
(
QWidget
):
class
ViewArea
(
QWidget
):
"""
Widget som kan byttes ut med view, edit etc.
"""
"""
Widget som kan byttes ut med view, edit etc.
"""
A4_RATIO
=
1.414
HEIGHT
=
1700
WIDTH
=
HEIGHT
*
A4_RATIO
PADDING
=
100
CONTENT_WIDTH
=
WIDTH
-
PADDING
*
2
CONTENT_HEIGHT
=
HEIGHT
-
PADDING
*
2
HEADER_HEIGHT
=
200
def
__init__
(
self
):
def
__init__
(
self
):
super
().
__init__
()
super
().
__init__
()
test
=
QLabel
(
"
Test
"
)
layout
=
QHBoxLayout
()
self
.
layout
=
QHBoxLayout
()
layout
.
addWidget
(
test
)
self
.
setLayout
(
layout
)
self
.
scene
=
QGraphicsScene
()
self
.
scene
.
setSceneRect
(
QRectF
(
0
,
0
,
self
.
WIDTH
,
self
.
HEIGHT
))
self
.
scene
.
addRect
(
0
,
0
,
self
.
WIDTH
,
self
.
HEIGHT
)
self
.
scene
.
addRect
(
self
.
PADDING
,
self
.
PADDING
,
self
.
CONTENT_WIDTH
,
self
.
CONTENT_HEIGHT
)
self
.
scene
.
addRect
(
self
.
PADDING
,
self
.
PADDING
,
self
.
CONTENT_WIDTH
,
self
.
HEADER_HEIGHT
)
self
.
view
=
QGraphicsView
(
self
.
scene
)
self
.
view
.
scale
(
0.50
,
0.50
)
self
.
layout
.
addWidget
(
self
.
view
)
self
.
setLayout
(
self
.
layout
)
self
.
launch_auto_zoom
()
def
launch_auto_zoom
(
self
):
"""
Zoom in a regular interval.
Used to demonstrate zooming only, should be removed once the project matures.
"""
def
do_on_timeout
():
self
.
zoom
(
1
/
1.00005
)
timer
=
QTimer
(
self
)
timer
.
timeout
.
connect
(
do_on_timeout
)
timer
.
start
(
10
)
def
zoom
(
self
,
zoom_factor
):
"""
Zoom GraphicsView by zoom_factor.
source: https://stackoverflow.com/a/29026916/3545896
Parameters
----------
zoom_factor : float
> 1 to zoom in and < 1 to zoom out
"""
# Set Anchors
self
.
view
.
setTransformationAnchor
(
QGraphicsView
.
NoAnchor
)
self
.
view
.
setResizeAnchor
(
QGraphicsView
.
NoAnchor
)
# Zoom
self
.
view
.
scale
(
zoom_factor
,
zoom_factor
)
pos_old
=
self
.
view
.
mapToScene
(
QPoint
(
self
.
WIDTH
/
2
,
self
.
HEIGHT
/
2
))
pos_new
=
self
.
view
.
mapToScene
(
self
.
WIDTH
/
2
,
self
.
HEIGHT
/
2
)
delta
=
pos_new
-
pos_old
self
.
view
.
translate
(
delta
.
x
(),
delta
.
y
())
app
=
QApplication
([])
app
=
QApplication
([])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment