0

I looked for solutions, but I did not find them. I wanted to make it into a QTimeEdit by pressing the up or down arrow on the minutes, and only those, step 10. I wanted to write in the stylesheet. I've tried these solutions, but they do not work.

QTimeEdit::MinuteSection{
stepBy:10;
}

QTimeEdit QAbstractSpinBox{
stepEnabled: True;
}

QTimeEdit QAbstractSpinBox::MinuteSection {
stepEnabled: True;
stepBy:10;
}

In all cases above the minutes always advance one and not 10. However, the code does not give me any errors. from PyQt5 import QtCore, QtGui, QtWidgets

class timeEdit(QtWidgets.QTimeEdit):
    def stepBy(self, steps):
        if self.currentSection() == self.MinuteSection:
            steps=10


class MainWindow(QtWidgets.QWidget):
    def __init__(self):#FFFFFF
        super(MainWindow, self).__init__()
        self.resize(800, 480)
        self.setWindowTitle("MainWindow")
        self.setObjectName("MainWindow")
        self.timeEdit = QtWidgets.QTimeEdit(self)
        self.timeEdit.setGeometry(QtCore.QRect(330, 30, 200, 100))
        self.timeEdit.stepBy(1)
        self.timeEdit2 = QtWidgets.QTimeEdit(self)
        self.timeEdit2.setGeometry(QtCore.QRect(330, 230, 200, 100))


if __name__ == "__main__":
    import sys
    app =QtWidgets.QApplication(sys.argv)

    Window= MainWindow()
    Window.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    main()
Vittorio
  • 1
  • 2

1 Answers1

0

The Qt Style Sheets only serve for the visual part, they do not handle the logic for it fails. The solution is to overwrite the stepBy() method of the QTimeEdit:

from PyQt5 import QtWidgets

class TimeEdit(QtWidgets.QTimeEdit):
    def stepBy(self, steps):
        if self.currentSection() == QtWidgets.QDateTimeEdit.MinuteSection:
            steps = 10
        super(TimeEdit, self).stepBy(steps)

if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = TimeEdit()
    w.show()
    sys.exit(app.exec_())
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • I have edited a new code, but it does not work I have 2 QTimeEdit the first must do the steps of the minutes, the secoda instead must be "normal". Surely I'm wrong, but I do not know what. Thanks for the attention. Vittorio – Vittorio Dec 24 '18 at 20:14
  • @Vittorio You forgot to add: `super(TimeEdit, self).stepBy(steps)` – eyllanesc Dec 24 '18 at 20:32
  • @Vittorio some feedback? – eyllanesc Dec 28 '18 at 02:30