UN-GCPDS / qt-material

Material inspired stylesheet for PySide2, PySide6, PyQt5 and PyQt6
https://qt-material.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
2.39k stars 253 forks source link

QDateEdit's popup is too small #73

Open oleschum opened 2 years ago

oleschum commented 2 years ago

When using a QDateEdit widget with popup (which is a QCalendarWidget), then the lower part of the popup is cut off, see image: qtmaterial_qdateedit_bug

Additionally, colors for days of the next month are not different from colors used for the days in the current month. The same holds true for days that are not available for selection (MinimumDate).

I work with Ubuntu 22.04, Pyside2 (same holds true for Pyside6), Python 3.10.

MWE to reproduce this:

from PySide2 import QtWidgets, QtCore
import qt_material

class DateEditGui(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        widget = QtWidgets.QWidget()
        self.vertical_layout = QtWidgets.QVBoxLayout()

        self.date_picker = QtWidgets.QDateEdit()
        self.date_picker.setDate(QtCore.QDate.currentDate())
        self.date_picker.setMinimumDate(QtCore.QDate.currentDate())
        self.date_picker.setCalendarPopup(True)

        self.vertical_layout.addWidget(self.date_picker)

        widget.setLayout(self.vertical_layout)
        self.setCentralWidget(widget)

app = QtWidgets.QApplication()
qt_material.apply_stylesheet(app, theme="dark_teal.xml")
window = DateEditGui()
window.show()
app.exec_()
josys36 commented 1 year ago

I've seen this issue too. Using a regular calendar widget works fine, but the popup in a QDateEdit is cut off slightly at the bottom.

gustavo-iniguez-goya commented 1 year ago

hey @josys36 @oleschum ,

You can use a custom CSS to temporary fix this issue:

from PyQt5 import QtWidgets, QtCore
import qt_material
import sys, os

class DateEditGui(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        widget = QtWidgets.QWidget()
        self.vertical_layout = QtWidgets.QVBoxLayout()

        self.date_picker = QtWidgets.QDateEdit()
        self.date_picker.setDate(QtCore.QDate.currentDate())
        self.date_picker.setMinimumDate(QtCore.QDate.currentDate())
        self.date_picker.setCalendarPopup(True)

        self.vertical_layout.addWidget(self.date_picker)

        widget.setLayout(self.vertical_layout)
        self.setCentralWidget(widget)

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    qt_material.apply_stylesheet(app, theme="dark_teal.xml")

    # load custom CSS
    stylesheet = app.styleSheet()
    with open('/tmp/custom.css') as file:
        app.setStyleSheet(stylesheet + file.read().format(**os.environ))
    ####################################################
    window = DateEditGui()
    window.show()
    app.exec_()

Create /tmp/custom.css with this content:

/*  QCalendarWidget  */

QCalendarWidget QAbstractItemView {{
    padding: 3px;
    margin: 3px;
}}
josys36 commented 1 year ago

It's actually easier to add,

QCalendarWidget QAbstractItemView { padding: 3px; margin: 3px; }

to material.css.template

That works too.

gustavo-iniguez-goya commented 1 year ago

you're right. The only problem is that it's not portable across computers. You should have to overwrite the file shipped with qt-material, which would be overwritten if the package is updated and does not include that change.

But anyway, that's the actually fix. Submit a PR! :)

josys36 commented 1 year ago

That is very true. Your method works well. Can one also use this method to adjust the font size for individual widgets? Like let's say I want a QLineEdit and QLabel to be a larger font, but I leave the font the default size on a QPushButton. If I adjust the font size globally the QPushButtons look too big. I tried using the Extras method provided, but the font size appears to go back to a default if you apply a style sheet to an individual widget.

josys36 commented 1 year ago

Honestly I think the best way to customize this is to just export the theme you are working with, and then make your changes there. I exported the dark amber theme and adjusted the calendar widget, and also made changes to QPushButton.

gustavo-iniguez-goya commented 1 year ago

I agree @josys36 . It'd be nice to have this little bug fixed btw

YeisonCardona commented 1 year ago

Hi, what do you think about setting a fixed minimum size?

QCalendarWidget {
  min-height: 300px;
}
gustavo-iniguez-goya commented 1 year ago

tested with latest v2.14 and this issue seems to be solved, @josys36 @oleschum , could you test it with latest release?