QInputDialog, Set the font for QPlainTextEdit and QLabel separately
-
QInputDialog, Set the font for QPlainTextEdit and QLabel separately
I want to set font size for this QPlainTextEdit only (not change QLabel font size), but no way.import sys from PySide2.QtGui import QFont from PySide2.QtWidgets import QInputDialog, QApplication, QWidget class MyInputDialog(QInputDialog): def __init__(self, parent, *args, **kwargs): super().__init__(parent, *args, **kwargs) self.setOption(QInputDialog.UsePlainTextEditForTextInput) self.setWindowTitle('title') self.setLabelText("label\nlabel") self.setTextValue('I want to set font size for this QPlainTextEdit only, but no way.') self.resize(600, 240) font = QFont() font.setFamily("Consolas") # font.setPointSize(10) # self.setFont(font) self.setStyleSheet("""QPlainTextEdit { font-size: 20; }""") class Widget(QWidget): def __init__(self, parent=None, *args, **kwargs): super().__init__(parent, *args, **kwargs) dialog = MyInputDialog(self) ok = dialog.exec() sys.exit(0) if __name__ == '__main__': app = QApplication(sys.argv) w = Widget() sys.exit(app.exec_())
cpp source code:
https://code.woboq.org/qt5/qtbase/src/widgets/dialogs/qinputdialog.cpp.htmlThe only way is to use a custom widget?
-
@ideaplus said in QInputDialog, Set the font for QPlainTextEdit and QLabel separately:
import sys
from PySide2.QtGui import QFont
from PySide2.QtWidgets import QInputDialog, QApplication, QWidgetclass MyInputDialog(QInputDialog):
def init(self, parent, *args, **kwargs):
super().init(parent, *args, **kwargs)
self.setOption(QInputDialog.UsePlainTextEditForTextInput)
self.setWindowTitle('title')
self.setLabelText("label\nlabel")
self.setTextValue('I want to set font size for this QPlainTextEdit only, but no way.')
self.resize(600, 240)
font = QFont()
font.setFamily("Consolas")
# font.setPointSize(10) #
self.setFont(font)
self.setStyleSheet("""QPlainTextEdit {
font-size: 20;
}""")class Widget(QWidget):
def init(self, parent=None, *args, **kwargs):
super().init(parent, *args, **kwargs)
dialog = MyInputDialog(self)
ok = dialog.exec()
sys.exit(0)if name == 'main':
app = QApplication(sys.argv)
w = Widget()
sys.exit(app.exec_())Font size without unit, add it.
font-size: 20pt; -
@ideaplus said in QInputDialog, Set the font for QPlainTextEdit and QLabel separately:
import sys
from PySide2.QtGui import QFont
from PySide2.QtWidgets import QInputDialog, QApplication, QWidgetclass MyInputDialog(QInputDialog):
def init(self, parent, *args, **kwargs):
super().init(parent, *args, **kwargs)
self.setOption(QInputDialog.UsePlainTextEditForTextInput)
self.setWindowTitle('title')
self.setLabelText("label\nlabel")
self.setTextValue('I want to set font size for this QPlainTextEdit only, but no way.')
self.resize(600, 240)
font = QFont()
font.setFamily("Consolas")
# font.setPointSize(10) #
self.setFont(font)
self.setStyleSheet("""QPlainTextEdit {
font-size: 20;
}""")class Widget(QWidget):
def init(self, parent=None, *args, **kwargs):
super().init(parent, *args, **kwargs)
dialog = MyInputDialog(self)
ok = dialog.exec()
sys.exit(0)if name == 'main':
app = QApplication(sys.argv)
w = Widget()
sys.exit(app.exec_())Font size without unit, add it.
font-size: 20pt; -
In C++ I would try to call something like
findChildren<QTextEdit*>()
on the dialog. I am not sure how this templated call would translate to Python, though. Then you could manipulate the text edit however you want.Otherwise the complete implementation of a new dialog suggested by @Denni-0 is the way to go.