Python PyQt5.QtGui.QFontMetrics() Examples
The following are 30 code examples for showing how to use PyQt5.QtGui.QFontMetrics(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
PyQt5.QtGui
, or try the search function
.
Example 1
Project: interSubs Author: oltodosel File: interSubs.py License: MIT License | 7 votes |
def highligting(self, color, underline_width): color = QColor(color) color = QColor(color.red(), color.green(), color.blue(), 200) painter = QPainter(self) if config.hover_underline: font_metrics = QFontMetrics(self.font()) text_width = font_metrics.width(self.word) text_height = font_metrics.height() brush = QBrush(color) pen = QPen(brush, underline_width, Qt.SolidLine, Qt.RoundCap) painter.setPen(pen) if not self.skip: painter.drawLine(0, text_height - underline_width, text_width, text_height - underline_width) if config.hover_hightlight: x = y = 0 y += self.fontMetrics().ascent() painter.setPen(color) painter.drawText(x, y + config.outline_top_padding - config.outline_bottom_padding, self.word)
Example 2
Project: dcc Author: amimo File: Banners.py License: Apache License 2.0 | 6 votes |
def __init__(self, themes, dataModel, viewMode): self.width = 0 self.height = 0 self.dataModel = dataModel self.viewMode = viewMode self.qpix = self._getNewPixmap(self.width, self.height) self.backgroundBrush = QtGui.QBrush(themes['background']) # text font self.font = themes['font'] # font metrics. assume font is monospaced self.font.setKerning(False) self.font.setFixedPitch(True) fm = QtGui.QFontMetrics(self.font) self.fontWidth = fm.width('a') self.fontHeight = fm.height() self.textPen = QtGui.QPen(QtGui.QColor(192, 192, 192), 0, QtCore.Qt.SolidLine)
Example 3
Project: dcc Author: amimo File: Banners.py License: Apache License 2.0 | 6 votes |
def __init__(self, themes, dataModel, viewMode): self.width = 0 self.height = 0 self.dataModel = dataModel self.viewMode = viewMode self.backgroundBrush = QtGui.QBrush(themes['background']) self.qpix = self._getNewPixmap(self.width, self.height) # text font self.font = themes['font'] # font metrics. assume font is monospaced self.font.setKerning(False) self.font.setFixedPitch(True) fm = QtGui.QFontMetrics(self.font) self.fontWidth = fm.width('a') self.fontHeight = fm.height() self.textPen = QtGui.QPen(themes['pen'], 0, QtCore.Qt.SolidLine)
Example 4
Project: qiew Author: mtivadar File: Banners.py License: GNU General Public License v2.0 | 6 votes |
def __init__(self, dataModel, viewMode): self.width = 0 self.height = 0 self.dataModel = dataModel self.viewMode = viewMode self.qpix = self._getNewPixmap(self.width, self.height) self.backgroundBrush = QtGui.QBrush(QtGui.QColor(0, 0, 128)) # text font self.font = QtGui.QFont('Terminus', 11, QtGui.QFont.Light) # font metrics. assume font is monospaced self.font.setKerning(False) self.font.setFixedPitch(True) fm = QtGui.QFontMetrics(self.font) self.fontWidth = fm.width('a') self.fontHeight = fm.height() self.textPen = QtGui.QPen(QtGui.QColor(192, 192, 192), 0, QtCore.Qt.SolidLine)
Example 5
Project: qiew Author: mtivadar File: Banners.py License: GNU General Public License v2.0 | 6 votes |
def __init__(self, dataModel, viewMode): self.width = 0 self.height = 0 self.dataModel = dataModel self.viewMode = viewMode self.qpix = self._getNewPixmap(self.width, self.height) self.backgroundBrush = QtGui.QBrush(QtGui.QColor(0, 0, 128)) # text font self.font = QtGui.QFont('Consolas', 11, QtGui.QFont.Light) # font metrics. assume font is monospaced self.font.setKerning(False) self.font.setFixedPitch(True) fm = QtGui.QFontMetrics(self.font) self.fontWidth = fm.width('a') self.fontHeight = fm.height() self.textPen = QtGui.QPen(QtGui.QColor(255, 255, 0), 0, QtCore.Qt.SolidLine)
Example 6
Project: qiew Author: mtivadar File: elf.py License: GNU General Public License v2.0 | 6 votes |
def __init__(self, dataModel, viewMode, elfplugin): self.width = 0 self.height = 0 self.dataModel = dataModel self.viewMode = viewMode self.qpix = self._getNewPixmap(self.width, self.height) self.backgroundBrush = QtGui.QBrush(QtGui.QColor(0, 0, 128)) self.elfplugin = elfplugin self.elf = self.elfplugin.elf # text font self.font = QtGui.QFont('Terminus', 11, QtGui.QFont.Bold) # font metrics. assume font is monospaced self.font.setKerning(False) self.font.setFixedPitch(True) fm = QtGui.QFontMetrics(self.font) self.fontWidth = fm.width('a') self.fontHeight = fm.height() self.textPen = QtGui.QPen(QtGui.QColor(192, 192, 192), 0, QtCore.Qt.SolidLine)
Example 7
Project: FeelUOwn Author: feeluown File: player_control_panel.py License: GNU General Public License v3.0 | 6 votes |
def on_player_song_changed(self, song): if song is None: self.song_source_label.setText('歌曲来源') self.song_title_label.setText('No song is playing.') return source_name_map = {p.identifier: p.name for p in self._app.library.list()} font_metrics = QFontMetrics(QApplication.font()) text = '{} - {}'.format(song.title_display, song.artists_name_display) # width -> three button + source label + text <= progress slider # three button: 63, source label: 150 elided_text = font_metrics.elidedText( text, Qt.ElideRight, self.progress_slider.width() - 200) self.song_source_label.setText(source_name_map[song.source]) self.song_title_label.setText(elided_text) loop = asyncio.get_event_loop() loop.create_task(self.update_mv_btn_status(song))
Example 8
Project: lanzou-gui Author: rachpt File: others.py License: MIT License | 6 votes |
def lineCountToWidgetHeight(self, num_lines): """ Returns the number of pixels corresponding to the height of specified number of lines in the default font. """ # ASSUMPTION: The document uses only the default font assert num_lines >= 0 widget_margins = self.contentsMargins() document_margin = self.document().documentMargin() font_metrics = QFontMetrics(self.document().defaultFont()) # font_metrics.lineSpacing() is ignored because it seems to be already included in font_metrics.height() return ( widget_margins.top() + document_margin + max(num_lines, 1) * font_metrics.height() + self.document().documentMargin() + widget_margins.bottom() )
Example 9
Project: MARA_Framework Author: xtiankisutsa File: Banners.py License: GNU Lesser General Public License v3.0 | 6 votes |
def __init__(self, themes, dataModel, viewMode): self.width = 0 self.height = 0 self.dataModel = dataModel self.viewMode = viewMode self.qpix = self._getNewPixmap(self.width, self.height) self.backgroundBrush = QtGui.QBrush(themes['background']) # text font self.font = themes['font'] # font metrics. assume font is monospaced self.font.setKerning(False) self.font.setFixedPitch(True) fm = QtGui.QFontMetrics(self.font) self.fontWidth = fm.width('a') self.fontHeight = fm.height() self.textPen = QtGui.QPen(QtGui.QColor(192, 192, 192), 0, QtCore.Qt.SolidLine)
Example 10
Project: MARA_Framework Author: xtiankisutsa File: Banners.py License: GNU Lesser General Public License v3.0 | 6 votes |
def __init__(self, themes, dataModel, viewMode): self.width = 0 self.height = 0 self.dataModel = dataModel self.viewMode = viewMode self.backgroundBrush = QtGui.QBrush(themes['background']) self.qpix = self._getNewPixmap(self.width, self.height) # text font self.font = themes['font'] # font metrics. assume font is monospaced self.font.setKerning(False) self.font.setFixedPitch(True) fm = QtGui.QFontMetrics(self.font) self.fontWidth = fm.width('a') self.fontHeight = fm.height() self.textPen = QtGui.QPen(themes['pen'], 0, QtCore.Qt.SolidLine)
Example 11
Project: urh Author: jopohl File: GeneratorTabController.py License: GNU General Public License v3.0 | 6 votes |
def on_table_selection_changed(self): min_row, max_row, start, end = self.ui.tableMessages.selection_range() if min_row == -1: self.ui.lEncodingValue.setText("-") # self.ui.lEncodingValue.setToolTip("") self.label_list_model.message = None return container = self.table_model.protocol message = container.messages[min_row] self.label_list_model.message = message decoder_name = message.decoder.name metrics = QFontMetrics(self.ui.lEncodingValue.font()) elidedName = metrics.elidedText(decoder_name, Qt.ElideRight, self.ui.lEncodingValue.width()) self.ui.lEncodingValue.setText(elidedName) self.ui.lEncodingValue.setToolTip(decoder_name) self.ui.cBoxModulations.blockSignals(True) self.ui.cBoxModulations.setCurrentIndex(message.modulator_index) self.show_modulation_info() self.ui.cBoxModulations.blockSignals(False)
Example 12
Project: dcc Author: amimo File: SourceViewMode.py License: Apache License 2.0 | 5 votes |
def __init__(self, themes, width, height, data, cursor, widget=None): super(SourceViewMode, self).__init__() self.themes = themes self.dataModel = data self.addHandler(self.dataModel) self.width = width self.height = height self.cursor = cursor self.widget = widget self.refresh = True # background brush self.backgroundBrush = QtGui.QBrush(self.themes['background']) # text font self.font = self.themes['font'] # font metrics. assume font is monospaced self.font.setKerning(False) self.font.setFixedPitch(True) fm = QtGui.QFontMetrics(self.font) self._fontWidth = fm.width('a') self._fontHeight = fm.height() self.textPen = QtGui.QPen(self.themes['pen'], 0, QtCore.Qt.SolidLine) self.resize(width, height) self.Paints = {} self.Ops = [] self.newPix = None self.selector = TextSelection.DefaultSelection(themes, self) self.LINES = self.dataModel.current_class.get_source().split('\n')
Example 13
Project: dcc Author: amimo File: cemu.py License: Apache License 2.0 | 5 votes |
def __init__(self, qp, rows, cols): self.qp = qp self._x = 0 self._y = 0 self._rows = rows self._cols = cols fm = QtGui.QFontMetrics(self.qp.font()) self.fontWidth = fm.width('a') self.fontHeight = fm.height()
Example 14
Project: dcc Author: amimo File: BinViewMode.py License: Apache License 2.0 | 5 votes |
def __init__(self, themes, width, height, data, cursor, widget=None): super(BinViewMode, self).__init__() self.dataModel = data self.addHandler(self.dataModel) self.themes = themes self.width = width self.height = height self.cursor = cursor self.widget = widget self.refresh = True self.selector = TextSelection.DefaultSelection(themes, self) # background brush self.backgroundBrush = QtGui.QBrush(self.themes['background']) self.font = self.themes['font'] # font metrics. assume font is monospaced self.font.setKerning(False) self.font.setFixedPitch(True) fm = QtGui.QFontMetrics(self.font) self._fontWidth = fm.width('a') self._fontHeight = fm.height() self.textPen = QtGui.QPen(self.themes['pen'], 0, QtCore.Qt.SolidLine) self.resize(width, height) self.Paints = {} self.newPix = None self.Ops = []
Example 15
Project: qiew Author: mtivadar File: cemu.py License: GNU General Public License v2.0 | 5 votes |
def __init__(self, qp, rows, cols): self.qp = qp self._x = 0 self._y = 0 self._rows = rows self._cols = cols fm = QtGui.QFontMetrics(self.qp.font()) self.fontWidth = fm.width('a') self.fontHeight = fm.height()
Example 16
Project: qiew Author: mtivadar File: BinViewMode.py License: GNU General Public License v2.0 | 5 votes |
def __init__(self, width, height, data, cursor, widget=None, plugin=None): super(BinViewMode, self).__init__() self.dataModel = data self.addHandler(self.dataModel) self.width = width self.height = height self.cursor = cursor self.widget = widget self.refresh = True self.selector = TextSelection.DefaultSelection(self) # background brush self.backgroundBrush = QtGui.QBrush(QtGui.QColor(0, 0, 128)) # text font #self.font = QtGui.QFont('Terminus (TTF)', 12, QtGui.QFont.Light) #self.font.setStyleHint(QtGui.QFont.AnyStyle, QtGui.QFont.PreferBitmap) self.font = QtGui.QFont('Terminus', 11, QtGui.QFont.Light) # font metrics. assume font is monospaced self.font.setKerning(False) self.font.setFixedPitch(True) fm = QtGui.QFontMetrics(self.font) self._fontWidth = fm.width('a') self._fontHeight = fm.height() self.textPen = QtGui.QPen(QtGui.QColor(192, 192, 192), 0, QtCore.Qt.SolidLine) self.resize(width, height) self.Paints = {} self.newPix = None self.Ops = [] self.plugin = plugin
Example 17
Project: qiew Author: mtivadar File: pe.py License: GNU General Public License v2.0 | 5 votes |
def __init__(self, dataModel, viewMode, peplugin): self.width = 0 self.height = 0 self.dataModel = dataModel self.viewMode = viewMode self.qpix = self._getNewPixmap(self.width, self.height) self.backgroundBrush = QtGui.QBrush(QtGui.QColor(0, 0, 128)) self.peplugin = peplugin initPE = True try: self.PE = pefile.PE(data=dataModel.getData()) except: initPE = False # text font self.font = QtGui.QFont('Terminus', 11, QtGui.QFont.Bold) # font metrics. assume font is monospaced self.font.setKerning(False) self.font.setFixedPitch(True) fm = QtGui.QFontMetrics(self.font) self.fontWidth = fm.width('a') self.fontHeight = fm.height() self.textPen = QtGui.QPen(QtGui.QColor(192, 192, 192), 0, QtCore.Qt.SolidLine) if initPE == False: return
Example 18
Project: MDT Author: robbert-harms File: tab_map_specific.py License: GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, controller, parent=None): super().__init__(parent) self.setupUi(self) self._controller = controller current_model = self._controller.get_model() self._current_map = None self.colormap.addItems(['-- Use global --'] + current_model.get_config().get_available_colormaps()) self.colormap.currentIndexChanged.connect(self._update_colormap) self.data_clipping_min.valueChanged.connect(self._update_clipping_min) self.data_clipping_max.valueChanged.connect(self._update_clipping_max) self.data_scale_min.valueChanged.connect(self._update_scale_min) self.data_scale_max.valueChanged.connect(self._update_scale_max) self.data_set_use_scale.stateChanged.connect(self._set_use_scale) self.use_data_scale_min.stateChanged.connect(self._set_use_data_scale_min) self.use_data_scale_max.stateChanged.connect(self._set_use_data_scale_max) self.data_set_use_clipping.stateChanged.connect(self._set_use_clipping) self.use_data_clipping_min.stateChanged.connect(self._set_use_data_clipping_min) self.use_data_clipping_max.stateChanged.connect(self._set_use_data_clipping_max) self._title_timer = TimedUpdate(self._update_map_title) self.map_title.textChanged.connect(lambda: self._title_timer.add_delayed_callback(500)) self.map_title.setFixedHeight(QFontMetrics(self.map_title.font()).lineSpacing() * 3) self._colorbar_label_timer = TimedUpdate(self._update_colorbar_label) self.data_colorbar_label.textChanged.connect(lambda : self._colorbar_label_timer.add_delayed_callback(500)) self.data_colorbar_label.setFixedHeight(QFontMetrics(self.data_colorbar_label.font()).lineSpacing() * 3) self.info_Clipping.set_collapse(True) self._auto_enable_scale_min = False self._auto_enable_scale_max = False self._auto_enable_clipping_min = False self._auto_enable_clipping_max = False self.reset() self._update_scaling_delays()
Example 19
Project: linux-show-player Author: FrancescoCeruti File: equalizer10.py License: GNU General Public License v3.0 | 5 votes |
def __init__(self, **kwargs): super().__init__(**kwargs) self.setLayout(QVBoxLayout()) self.layout().setAlignment(Qt.AlignTop) self.groupBox = QGroupBox(self) self.groupBox.resize(self.size()) self.groupBox.setTitle( translate('Equalizer10Settings', '10 Bands Equalizer (IIR)')) self.groupBox.setLayout(QGridLayout()) self.groupBox.layout().setVerticalSpacing(0) self.layout().addWidget(self.groupBox) self.sliders = {} for n in range(10): label = QLabel(self.groupBox) label.setMinimumWidth(QFontMetrics(label.font()).width('000')) label.setAlignment(QtCore.Qt.AlignCenter) label.setNum(0) self.groupBox.layout().addWidget(label, 0, n) slider = QSlider(self.groupBox) slider.setRange(-24, 12) slider.setPageStep(1) slider.setValue(0) slider.setOrientation(QtCore.Qt.Vertical) slider.valueChanged.connect(label.setNum) self.groupBox.layout().addWidget(slider, 1, n) self.groupBox.layout().setAlignment(slider, QtCore.Qt.AlignHCenter) self.sliders['band' + str(n)] = slider fLabel = QLabel(self.groupBox) fLabel.setStyleSheet('font-size: 8pt;') fLabel.setAlignment(QtCore.Qt.AlignCenter) fLabel.setText(self.FREQ[n]) self.groupBox.layout().addWidget(fLabel, 2, n)
Example 20
Project: Uranium Author: Ultimaker File: Theme.py License: GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, engine, parent = None) -> None: super().__init__(parent) self._engine = engine self._styles = None # type: Optional[QObject] self._path = "" self._icons = {} # type: Dict[str, QUrl] self._images = {} # type: Dict[str, QUrl] # Workaround for incorrect default font on Windows if sys.platform == "win32": default_font = QFont() default_font.setPointSize(9) QCoreApplication.instance().setFont(default_font) self._em_height = int(QFontMetrics(QCoreApplication.instance().font()).ascent()) self._em_width = self._em_height # Cache the initial language in the preferences. For fonts, a special font can be defined with, for example, # "medium" and "medium_nl_NL". If the special one exists, getFont() will return that, otherwise the default # will be returned. We cache the initial language here is because Cura can only change its language if it gets # restarted, so we need to keep the fonts consistent in a single Cura run. self._preferences = UM.Application.Application.getInstance().getPreferences() self._lang_code = self._preferences.getValue("general/language") self._initializeDefaults() self.reload()
Example 21
Project: Uranium Author: Ultimaker File: QtApplication.py License: GNU Lesser General Public License v3.0 | 5 votes |
def _screenScaleFactor(self) -> float: # OSX handles sizes of dialogs behind our backs, but other platforms need # to know about the device pixel ratio if sys.platform == "darwin": return 1.0 else: # determine a device pixel ratio from font metrics, using the same logic as UM.Theme fontPixelRatio = QFontMetrics(QCoreApplication.instance().font()).ascent() / 11 # round the font pixel ratio to quarters fontPixelRatio = int(fontPixelRatio * 4) / 4 return fontPixelRatio
Example 22
Project: Miyamoto Author: aboood40091 File: misc.py License: GNU General Public License v3.0 | 5 votes |
def clipStr(text, idealWidth, font=None): """ Returns a shortened string, or None if it need not be shortened """ if font is None: font = QtGui.QFont() width = QtGui.QFontMetrics(font).width(text) if width <= idealWidth: return None while width > idealWidth: text = text[:-1] width = QtGui.QFontMetrics(font).width(text) return text
Example 23
Project: Miyamoto Author: aboood40091 File: stamp.py License: GNU General Public License v3.0 | 5 votes |
def calculateTextSize(text): """ Calculates the size of text. Crops to 96 pixels wide. """ fontMetrics = QtGui.QFontMetrics(QtGui.QFont()) fontRect = fontMetrics.boundingRect(QtCore.QRect(0, 0, 96, 48), Qt.TextWordWrap, text) w, h = fontRect.width(), fontRect.height() return QtCore.QSizeF(min(w, 96), h)
Example 24
Project: mkYARA Author: fox-it File: mkyara_plugin.py License: GNU General Public License v3.0 | 5 votes |
def populate_form(self): self.setWindowTitle('mkYARA :: Generated Yara Rule') self.resize(800, 600) self.layout = QtWidgets.QVBoxLayout(self) self.top_layout = QtWidgets.QHBoxLayout() self.bottom_layout = QtWidgets.QHBoxLayout() self.bottom_layout.setAlignment(Qt.AlignRight | Qt.AlignBottom) # layout.addStretch() self.layout.addWidget(QtWidgets.QLabel("Generated Yara rule from 0x{:x} to 0x{:x}".format(self.start_addr, self.end_addr))) self.text_edit = QtWidgets.QTextEdit() font = QtGui.QFont() font.setFamily("Consolas") font.setStyleHint(QtGui.QFont.Monospace) font.setFixedPitch(True) font.setPointSize(10) self.text_edit.setFont(font) metrics = QtGui.QFontMetrics(font) self.text_edit.setTabStopWidth(4 * metrics.width(' ')) self.text_edit.insertPlainText(self.yara_rule) self.layout.addWidget(self.text_edit) self.ok_btn = QtWidgets.QPushButton("OK") self.ok_btn.setFixedWidth(100) self.ok_btn.clicked.connect(self.ok_btn_clicked) self.bottom_layout.addWidget(self.ok_btn) self.layout.addLayout(self.top_layout) self.layout.addLayout(self.bottom_layout)
Example 25
Project: crossCobra Author: morten1982 File: codeeditor.py License: MIT License | 5 votes |
def resetPythonPrintStyle(self, lexer): self.font = QFont() system = platform.system().lower() if system == 'windows': self.font.setFamily('Consolas') else: self.font.setFamily('Monospace') self.font.setFixedPitch(True) self.font.setPointSize(self.pointSize) self.setFont(self.font) lexer.setFont(self.font) # set Lexer self.setLexer(lexer) # margins reset # Margin 0 is used for line numbers fontmetrics = QFontMetrics(self.font) self.setMarginsFont(self.font) self.setMarginWidth(0, fontmetrics.width("00000") + 5) self.setMarginLineNumbers(0, True) self.setMarginsBackgroundColor(QColor("#000000")) self.setMarginsForegroundColor(QColor("#FFFFFF")) # FoldingBox self.setFoldMarginColors(QColor('dark green'), QColor('dark green'))
Example 26
Project: MARA_Framework Author: xtiankisutsa File: SourceViewMode.py License: GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, themes, width, height, data, cursor, widget=None): super(SourceViewMode, self).__init__() self.themes = themes self.dataModel = data self.addHandler(self.dataModel) self.width = width self.height = height self.cursor = cursor self.widget = widget self.refresh = True # background brush self.backgroundBrush = QtGui.QBrush(self.themes['background']) # text font self.font = self.themes['font'] # font metrics. assume font is monospaced self.font.setKerning(False) self.font.setFixedPitch(True) fm = QtGui.QFontMetrics(self.font) self._fontWidth = fm.width('a') self._fontHeight = fm.height() self.textPen = QtGui.QPen(self.themes['pen'], 0, QtCore.Qt.SolidLine) self.resize(width, height) self.Paints = {} self.Ops = [] self.newPix = None self.selector = TextSelection.DefaultSelection(themes, self) self.LINES = self.dataModel.current_class.get_source().split('\n')
Example 27
Project: MARA_Framework Author: xtiankisutsa File: cemu.py License: GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, qp, rows, cols): self.qp = qp self._x = 0 self._y = 0 self._rows = rows self._cols = cols fm = QtGui.QFontMetrics(self.qp.font()) self.fontWidth = fm.width('a') self.fontHeight = fm.height()
Example 28
Project: MARA_Framework Author: xtiankisutsa File: BinViewMode.py License: GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, themes, width, height, data, cursor, widget=None): super(BinViewMode, self).__init__() self.dataModel = data self.addHandler(self.dataModel) self.themes = themes self.width = width self.height = height self.cursor = cursor self.widget = widget self.refresh = True self.selector = TextSelection.DefaultSelection(themes, self) # background brush self.backgroundBrush = QtGui.QBrush(self.themes['background']) self.font = self.themes['font'] # font metrics. assume font is monospaced self.font.setKerning(False) self.font.setFixedPitch(True) fm = QtGui.QFontMetrics(self.font) self._fontWidth = fm.width('a') self._fontHeight = fm.height() self.textPen = QtGui.QPen(self.themes['pen'], 0, QtCore.Qt.SolidLine) self.resize(width, height) self.Paints = {} self.newPix = None self.Ops = []
Example 29
Project: Hydra Author: CountryTk File: Messagebox.py License: GNU General Public License v3.0 | 5 votes |
def resize_contents(self): text = self.text() font = QFont("", 0) metrics = QFontMetrics(font) width = metrics.width(text) height = metrics.height() self.setMinimumWidth(width + 40) self.setMinimumHeight(height + 15)
Example 30
Project: bidscoin Author: Donders-Institute File: bidseditor.py License: GNU General Public License v3.0 | 5 votes |
def __init__(self, filename: Path, sourcedict, dataformat: str): super().__init__() icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(str(ICON_FILENAME)), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.setWindowIcon(icon) self.setWindowTitle(f"Inspect {dataformat} file") layout = QVBoxLayout(self) label_path = QLabel(f"Path: {filename.parent}") label_path.setWordWrap(True) label_path.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse) layout.addWidget(label_path) label = QLabel(f"Filename: {filename.name}") label.setWordWrap(True) label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse) layout.addWidget(label) text = str(sourcedict) textBrowser = QTextBrowser(self) textBrowser.setFont(QtGui.QFont("Courier New")) textBrowser.insertPlainText(text) textBrowser.setLineWrapMode(QtWidgets.QTextEdit.NoWrap) self.scrollbar = textBrowser.verticalScrollBar() # For setting the slider to the top (can only be done after self.show() layout.addWidget(textBrowser) buttonBox = QDialogButtonBox(self) buttonBox.setStandardButtons(QDialogButtonBox.Ok) buttonBox.button(QDialogButtonBox.Ok).setToolTip('Close this window') layout.addWidget(buttonBox) # Set the width to the width of the text fontMetrics = QtGui.QFontMetrics(textBrowser.font()) textwidth = fontMetrics.size(0, text).width() self.resize(min(textwidth + 70, 1200), self.height()) buttonBox.accepted.connect(self.close)