Giter Club home page Giter Club logo

Comments (1)

RiekeJ avatar RiekeJ commented on June 8, 2024

Describe Your Environment

QDarkStyle: 3.0.2 and also 3.1 from PyPi

OS: Windows 10 22H2
Language
Python 3.9.12
PyQt5 5.15.7

Description / Steps to Reproduce [if necessary]
Vertical and horizontal header font and font size in QTableView are not adjusted if QDarkStyle is used . Changes are as expected if standard style is used.

minimum working example:

# inspired by https://www.pythonguis.com/tutorials/qtableview-modelviews-numpy-pandas/
import sys
import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import Qt
import qdarkstyle

class TableModel(QtCore.QAbstractTableModel):
    def __init__(self, data, horizontal_headers,**kwargs):
        super(TableModel, self).__init__()
        self._data = data
        self._horizontal_headers = horizontal_headers
        
        if 'font' in kwargs.keys():            
            self._font = QtGui.QFont(kwargs['font'])
        else:
            self._font = QtGui.QFont()  
                
        if 'fontsize' in kwargs.keys():
            self._font.setPixelSize(kwargs['fontsize'])
        else:
            self._font.setPixelSize(12)

    def data(self, index, role) -> str:
        """method for visualization of the data model"""        
        # display
        if role == Qt.DisplayRole:
            datum = self._data[index.row(),index.column()]            
            return str(datum)
        # set fonts
        if role == Qt.FontRole:
            return self._font              

    def rowCount(self, index):
        return self._data.shape[0]

    def columnCount(self, index):
        return self._data.shape[1]        
        
    def headerData(self, section, orientation, role):        
        # section is the index of the column/row.
        if role == Qt.DisplayRole:
            if orientation == Qt.Horizontal:
                return str(self._horizontal_headers[section])

            if orientation == Qt.Vertical:                
                return str(section)
                
        # set fonts for headers
        if role == Qt.FontRole:
            return self._font        

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        self.table = QtWidgets.QTableView()
        data = np.array([
          [4, 9, 2],
          [1, 0, 0],
          [3, 5, 0],
          [3, 3, 2],
          [7, 8, 9],
        ],dtype=int)
        self.model = TableModel(data,['A','B','C'],font='Arial', fontsize=9)
        self.table.setModel(self.model)
        self.setCentralWidget(self.table)

if __name__ == "__main__":
    app=QtWidgets.QApplication(sys.argv)
    dark_stylesheet = qdarkstyle.load_stylesheet_pyqt5()
    app.setStyleSheet(dark_stylesheet)    
    window=MainWindow()
    window.show()
    app.exec_()

Actual Results
Header do not change by request.

Expected Results / Proposed Result
Headers should change font and font size as well as table data.

Commenting out

   dark_stylesheet = qdarkstyle.load_stylesheet_pyqt5()
   app.setStyleSheet(dark_stylesheet)

and using standard style works as intended.

from qdarkstylesheet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.