mirror of
https://github.com/pyapp-kit/superqt.git
synced 2025-12-16 11:10:06 +01:00
Add QElidingLineEdit class for elidable QLineEdits (#154)
* Add QElidingLineEdit class for elidable QLineEdits * Fix QElidingLineEdit tests on Linux and MacOS * Testing --------- Co-authored-by: Talley Lambert <talley.lambert@gmail.com>
This commit is contained in:
committed by
GitHub
parent
6318675a8c
commit
9119336de5
@@ -31,14 +31,14 @@ def test_wrapped_eliding_label(qtbot):
|
||||
qtbot.addWidget(wdg)
|
||||
assert not wdg.wordWrap()
|
||||
assert 630 < wdg.sizeHint().width() < 640
|
||||
assert wdg._elidedText().endswith("…")
|
||||
assert wdg._elidedText().endswith(ELLIPSIS)
|
||||
wdg.resize(QSize(200, 100))
|
||||
assert wdg.text() == TEXT
|
||||
assert wdg._elidedText().endswith("…")
|
||||
assert wdg._elidedText().endswith(ELLIPSIS)
|
||||
wdg.setWordWrap(True)
|
||||
assert wdg.wordWrap()
|
||||
assert wdg.text() == TEXT
|
||||
assert wdg._elidedText().endswith("…")
|
||||
assert wdg._elidedText().endswith(ELLIPSIS)
|
||||
# just empirically from CI ... stupid
|
||||
if platform.system() == "Linux":
|
||||
assert wdg.sizeHint() in (QSize(200, 198), QSize(200, 154))
|
||||
|
||||
60
tests/test_eliding_line_edit.py
Normal file
60
tests/test_eliding_line_edit.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from qtpy.QtCore import QSize, Qt
|
||||
from qtpy.QtGui import QResizeEvent
|
||||
|
||||
from superqt import QElidingLineEdit
|
||||
|
||||
TEXT = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do"
|
||||
ELLIPSIS = "…"
|
||||
|
||||
|
||||
def test_init_text_eliding_line_edit(qtbot):
|
||||
wdg = QElidingLineEdit(TEXT)
|
||||
qtbot.addWidget(wdg)
|
||||
oldsize = QSize(100, 20)
|
||||
wdg.resize(oldsize)
|
||||
assert wdg._elidedText().endswith(ELLIPSIS)
|
||||
newsize = QSize(500, 20)
|
||||
wdg.resize(newsize)
|
||||
wdg.resizeEvent(QResizeEvent(oldsize, newsize)) # for test coverage
|
||||
assert wdg._elidedText() == TEXT
|
||||
assert wdg.text() == TEXT
|
||||
|
||||
|
||||
def test_set_text_eliding_line_edit(qtbot):
|
||||
wdg = QElidingLineEdit()
|
||||
qtbot.addWidget(wdg)
|
||||
wdg.resize(500, 20)
|
||||
wdg.setText(TEXT)
|
||||
assert not wdg._elidedText().endswith(ELLIPSIS)
|
||||
wdg.resize(100, 20)
|
||||
assert wdg._elidedText().endswith(ELLIPSIS)
|
||||
|
||||
|
||||
def test_set_elide_mode_eliding_line_edit(qtbot):
|
||||
wdg = QElidingLineEdit()
|
||||
qtbot.addWidget(wdg)
|
||||
wdg.resize(500, 20)
|
||||
wdg.setText(TEXT)
|
||||
assert not wdg._elidedText().endswith(ELLIPSIS)
|
||||
wdg.resize(100, 20)
|
||||
# ellipses should be to the right
|
||||
assert wdg._elidedText().endswith(ELLIPSIS)
|
||||
|
||||
# ellipses should be to the left
|
||||
wdg.setElideMode(Qt.TextElideMode.ElideLeft)
|
||||
assert wdg._elidedText().startswith(ELLIPSIS)
|
||||
assert wdg.elideMode() == Qt.TextElideMode.ElideLeft
|
||||
|
||||
# no ellipses should be shown
|
||||
wdg.setElideMode(Qt.TextElideMode.ElideNone)
|
||||
assert ELLIPSIS not in wdg._elidedText()
|
||||
|
||||
|
||||
def test_set_elipses_width_eliding_line_edit(qtbot):
|
||||
wdg = QElidingLineEdit()
|
||||
qtbot.addWidget(wdg)
|
||||
wdg.resize(500, 20)
|
||||
wdg.setText(TEXT)
|
||||
assert not wdg._elidedText().endswith(ELLIPSIS)
|
||||
wdg.setEllipsesWidth(int(wdg.width() / 2))
|
||||
assert wdg._elidedText().endswith(ELLIPSIS)
|
||||
Reference in New Issue
Block a user