def add_header(name):
     heading_ui = QListWidgetItem(name)
     heading_ui.setFlags(Qt.ItemIsEnabled)
     heading_ui.setSizeHint(
         QSize(self.form.list_personal_fields.width(), 30))
     heading_ui.setFont(heading_font)
     self.form.list_personal_fields.addItem(heading_ui)
Exemple #2
0
    def sizeHint(self, option, index):
        options = QStyleOptionViewItemV4(option)
        self.initStyleOption(options, index)

        # Get sizeof the elements
        doc = QTextDocument()
        doc.setHtml(options.text)
        doc.setTextWidth(options.rect.width())
        return QSize(doc.idealWidth(), doc.size().height())
    def sizeHint(self, option, index):
        """Overrided."""
        text = index.data(Qt.DisplayRole)
        treeView = option.styleObject
        width = treeView.columnWidth(0) - treeView.indentation() * 3

        self._setupTextDocument(text, width)
        return QSize(self.textDocument.idealWidth(),
                     self.textDocument.size().height())
Exemple #4
0
 def _updateButtonColor(self, color):
     """Generate color preview pixmap and place it on button"""
     pixmap = QPixmap(128, 18)
     qcolour = QColor(0, 0, 0)
     qcolour.setNamedColor(color)
     pixmap.fill(qcolour)
     self.setIcon(QIcon(pixmap))
     self.setIconSize(QSize(128, 18))
     self.color = color
Exemple #5
0
 def _addDockable(self, title, w):
     dock = DockableWithClose(title, self.mw)
     dock.setObjectName(title)
     dock.setAllowedAreas(Qt.DockWidgetArea.LeftDockWidgetArea | Qt.DockWidgetArea.RightDockWidgetArea)
     dock.setFeatures(QDockWidget.DockWidgetFeature.DockWidgetClosable)
     dock.setWidget(w)
     if self.mw.width() < 600:
         self.mw.resize(QSize(600, self.mw.height()))
     self.mw.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, dock)
     if self.night_mode_on:
         # https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qdockwidget
         # I think I can't style the divider since this like a window border which are
         # owned by the OS?
         # A QSplitter can be styled but I think this would require to
         # change main.py/setupMainWindow which I don't want to do.
         dock.setStyleSheet("""
         QWidget::title {
             color: white;
             background-color: #272828;
         }
         """)
     return dock
Exemple #6
0
def ensureWidgetInScreenBoundaries(widget):
    handle = widget.window().windowHandle()
    if not handle:
        # window has not yet been shown, retry later
        aqt.mw.progress.timer(50, lambda: ensureWidgetInScreenBoundaries(widget), False)
        return

    # ensure widget is smaller than screen bounds
    geom = handle.screen().availableGeometry()
    wsize = widget.size()
    cappedWidth = min(geom.width(), wsize.width())
    cappedHeight = min(geom.height(), wsize.height())
    if cappedWidth > wsize.width() or cappedHeight > wsize.height():
        widget.resize(QSize(cappedWidth, cappedHeight))

    # ensure widget is inside top left
    wpos = widget.pos()
    x = max(geom.x(), wpos.x())
    y = max(geom.y(), wpos.y())
    # and bottom right
    x = min(x, geom.width()+geom.x()-cappedWidth)
    y = min(y, geom.height()+geom.y()-cappedHeight)
    if x != wpos.x() or y != wpos.y():
        widget.move(x, y)
Exemple #7
0
 def sizeHint(self):
     return QSize(gc("default width", 200), 100)