Don't grow window when track title too long
Use an elided text box, set wrapping and max height for label. Fixes #26
This commit is contained in:
parent
246b0d4915
commit
0e3e30391b
@ -10,11 +10,13 @@ from datetime import datetime, timedelta
|
||||
from log import DEBUG, EXCEPTION
|
||||
|
||||
from PyQt5.QtCore import Qt, QTimer
|
||||
from PyQt5.QtGui import QFontMetrics, QPainter
|
||||
from PyQt5.QtWidgets import (
|
||||
QApplication,
|
||||
QDialog,
|
||||
QFileDialog,
|
||||
QInputDialog,
|
||||
QLabel,
|
||||
QListWidgetItem,
|
||||
QMainWindow,
|
||||
)
|
||||
@ -32,6 +34,21 @@ from ui.dlg_SelectPlaylist_ui import Ui_dlgSelectPlaylist
|
||||
from ui.main_window_ui import Ui_MainWindow
|
||||
|
||||
|
||||
class ElideLabel(QLabel):
|
||||
"""
|
||||
From https://stackoverflow.com/questions/11446478/
|
||||
pyside-pyqt-truncate-text-in-qlabel-based-on-minimumsize
|
||||
"""
|
||||
|
||||
def paintEvent(self, event):
|
||||
painter = QPainter(self)
|
||||
|
||||
metrics = QFontMetrics(self.font())
|
||||
elided = metrics.elidedText(self.text(), Qt.ElideRight, self.width())
|
||||
|
||||
painter.drawText(self.rect(), self.alignment(), elided)
|
||||
|
||||
|
||||
class Window(QMainWindow, Ui_MainWindow):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
@ -149,6 +149,9 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -166,10 +169,25 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="hdrNextTrack">
|
||||
<widget class="ElideLabel" name="hdrNextTrack">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>39</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>39</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Sans</family>
|
||||
@ -183,6 +201,9 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@ -984,6 +1005,13 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ElideLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header>musicmuster</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="icons.qrc"/>
|
||||
</resources>
|
||||
|
||||
@ -85,6 +85,7 @@ class Ui_MainWindow(object):
|
||||
self.hdrPreviousTrack.setStyleSheet("background-color: #f8d7da;\n"
|
||||
"border: 1px solid rgb(85, 87, 83);")
|
||||
self.hdrPreviousTrack.setText("")
|
||||
self.hdrPreviousTrack.setWordWrap(True)
|
||||
self.hdrPreviousTrack.setObjectName("hdrPreviousTrack")
|
||||
self.verticalLayout.addWidget(self.hdrPreviousTrack)
|
||||
self.hdrCurrentTrack = QtWidgets.QLabel(self.centralwidget)
|
||||
@ -95,9 +96,12 @@ class Ui_MainWindow(object):
|
||||
self.hdrCurrentTrack.setStyleSheet("background-color: #d4edda;\n"
|
||||
"border: 1px solid rgb(85, 87, 83);")
|
||||
self.hdrCurrentTrack.setText("")
|
||||
self.hdrCurrentTrack.setWordWrap(True)
|
||||
self.hdrCurrentTrack.setObjectName("hdrCurrentTrack")
|
||||
self.verticalLayout.addWidget(self.hdrCurrentTrack)
|
||||
self.hdrNextTrack = QtWidgets.QLabel(self.centralwidget)
|
||||
self.hdrNextTrack = ElideLabel(self.centralwidget)
|
||||
self.hdrNextTrack.setMinimumSize(QtCore.QSize(0, 39))
|
||||
self.hdrNextTrack.setMaximumSize(QtCore.QSize(16777215, 39))
|
||||
font = QtGui.QFont()
|
||||
font.setFamily("Sans")
|
||||
font.setPointSize(20)
|
||||
@ -105,6 +109,7 @@ class Ui_MainWindow(object):
|
||||
self.hdrNextTrack.setStyleSheet("background-color: #fff3cd;\n"
|
||||
"border: 1px solid rgb(85, 87, 83);")
|
||||
self.hdrNextTrack.setText("")
|
||||
self.hdrNextTrack.setWordWrap(True)
|
||||
self.hdrNextTrack.setObjectName("hdrNextTrack")
|
||||
self.verticalLayout.addWidget(self.hdrNextTrack)
|
||||
self.horizontalLayout_3.addLayout(self.verticalLayout)
|
||||
@ -540,4 +545,5 @@ class Ui_MainWindow(object):
|
||||
self.actionSelect_previous_track.setShortcut(_translate("MainWindow", "K"))
|
||||
self.actionSelect_played_tracks.setText(_translate("MainWindow", "Select played tracks"))
|
||||
self.actionSelect_unplayed_tracks.setText(_translate("MainWindow", "Select unplayed tracks"))
|
||||
from musicmuster import ElideLabel
|
||||
import icons_rc
|
||||
|
||||
Loading…
Reference in New Issue
Block a user