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
b7d6fcbb
Commit
b7d6fcbb
authored
4 years ago
by
morkolai
Browse files
Options
Downloads
Patches
Plain Diff
#96 WIP Prøvde å bruke TextEditWithSizeOfcontent
parent
c8859675
No related branches found
Branches containing commit
No related tags found
1 merge request
!57
#96 Telefonliste & Fiks til høyde på tabeller (rundt oppløsning)
Pipeline
#81866
failed
4 years ago
Stage: lint
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
soitool/modules/module_phonebook.py
+38
-19
38 additions, 19 deletions
soitool/modules/module_phonebook.py
with
38 additions
and
19 deletions
soitool/modules/module_phonebook.py
+
38
−
19
View file @
b7d6fcbb
...
...
@@ -149,6 +149,39 @@ class PhoneTable(QTableWidget):
return
QSize
(
width
,
heigth
)
class
TextEditWithSizeOfContent
(
QTextEdit
):
"""
Custom QTextEdit subclass that grows to fit it
'
s text.
"""
def
__init__
(
self
,
*
arg
,
**
kwargs
):
super
(
TextEditWithSizeOfContent
,
self
).
__init__
(
*
arg
,
**
kwargs
)
self
.
setSizePolicy
(
QSizePolicy
.
Minimum
,
QSizePolicy
.
Fixed
)
self
.
setHorizontalScrollBarPolicy
(
Qt
.
ScrollBarAlwaysOff
)
self
.
setVerticalScrollBarPolicy
(
Qt
.
ScrollBarAlwaysOff
)
# self.setLineWrapMode(QTextEdit.NoWrap)
def
sizeHint
(
self
,
h
):
"""
Give size hint using width of text.
"""
size
=
QSize
(
self
.
document
().
size
().
toSize
())
# NOTE that the following is not respected for dimensions below 100,100
size
.
setWidth
(
max
(
10
,
self
.
table
.
get_needed_size
().
width
()))
size
.
setHeight
(
max
(
100
,
size
.
height
()))
return
size
def
resizeEvent
(
self
,
event
):
"""
Update geometry before handling the resizeEvent.
See sources in module docstring.
Parameters
----------
event : QResizeEvent
event sent by Qt
"""
self
.
updateGeometry
()
super
(
TextEditWithSizeOfContent
,
self
).
resizeEvent
(
event
)
class
ComponentsPopup
(
QDialog
):
def
__init__
(
self
):
super
().
__init__
()
...
...
@@ -291,7 +324,7 @@ class PhonebookModule(ModuleBase, QWidget, metaclass=Meta):
self
.
layout
.
addWidget
(
self
.
table
)
self
.
layout
.
addWidget
(
self
.
help_text
)
self
.
layout
.
addLayout
(
self
.
buttons
)
self
.
layout
.
setAlignment
(
Qt
.
AlignLeft
)
self
.
layout
.
setAlignment
(
Qt
.
AlignLeft
|
Qt
.
AlignTop
)
self
.
setLayout
(
self
.
layout
)
def
__create_usage_help_text
(
self
):
...
...
@@ -303,26 +336,12 @@ class PhonebookModule(ModuleBase, QWidget, metaclass=Meta):
textfield belonding to the table
"""
txt
=
"
Insert text here
"
help_text
=
Q
TextEdit
()
help_text
=
TextEdit
WithSizeOfContent
()
help_text
.
setPlaceholderText
(
txt
)
def
resize_help_text
():
help_text
.
setFixedWidth
(
self
.
table
.
get_needed_size
().
width
())
L
=
len
(
help_text
.
toPlainText
())
We
=
help_text
.
fontWeight
()
Wi
=
self
.
table
.
get_needed_size
().
width
()
foo
=
(
L
*
We
)
/
Wi
if
foo
<
30
:
help_text
.
setFixedHeight
(
100
)
else
:
help_text
.
setFixedHeight
(
foo
*
3.3
)
resize_help_text
()
# help_text.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
help_text
.
cursorPositionChanged
.
connect
(
lambda
:
resize_help_text
())
help_text
.
cursorPositionChanged
.
connect
(
lambda
:
(
help_text
.
sizeHint
(),
help_text
.
adjustSize
())
)
return
help_text
...
...
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