0
    # Az adatokat tartalmazó txt fájlok nevei és elérési útvonalai
    dir_path = r"\\fgmhome4\SZEGED CC\CC írható\ÉD DSO\Scannelés\Patrik\EDDSO"  # Az adott mappa elérési útvonala
    txt_files = [os.path.join(dir_path, f) for f in os.listdir(dir_path) if f.endswith('.txt')]

    # Create the QApplication
    app = QApplication([])
    app.setWindowIcon(QIcon(r"C:\Users\fodorp3\Downloads\medal.png"))

    # Set the application style to the Fusion style
    app.setStyle(QStyleFactory.create("Fusion"))

    # A táblázat inicializálása
    table = QTableWidget()
    table.setFixedSize(500, 600)
    table.setShowGrid(False)
    table.setWindowTitle("Ranglista")
    table.setColumnCount(2)
    table.setHorizontalHeaderLabels(["Név", "Pontszám"])
    table.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
    table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Fixed)
    table.setEditTriggers(QTableWidget.NoEditTriggers)
    def generate_random_name():
        names = ['Laci', 'Jóska', 'Bence', 'Patrik', 'Gandalf', 'Pista', 'Julia', 'Sophie', 'Lucas', 'Oliver', 'Jenőke']
        return random.choice(names)

    # Az adatok feltöltése a táblázatba
    for i, txt_file in enumerate(txt_files):
        if os.path.exists(txt_file):
            with open(txt_file, "r") as f:
                data = f.read().splitlines()
                max_line_number = len(data)
            table.insertRow(i)
    
            # Icon hozzáadása az első oszlophoz
            if i < 1:
                icon = QIcon(r"C:\Users\fodorp3\Downloads\Iconshock-Batman-Dark-Night-Batman.ico")
                table.setItem(i, 0, QTableWidgetItem(icon, generate_random_name()))
            elif i < 2:
                icon = QIcon(r"C:\Users\fodorp3\Downloads\medal (1).png")
                table.setItem(i, 0, QTableWidgetItem(icon, generate_random_name()))
            elif i < 3:
                icon = QIcon(r"C:\Users\fodorp3\Downloads\medal (2).png")
                table.setItem(i, 0, QTableWidgetItem(icon, generate_random_name()))
            else:
                table.setItem(i, 0, QTableWidgetItem(generate_random_name()))
            table.setItem(i, 1, QTableWidgetItem(str(max_line_number)))
    # Set the table style
    table.setStyleSheet("""
        QTableWidget {
            background-color: white;
            alternate-background-color: #f2f2f2;
            gridline-color: #ccc;
            selection-color: white;
            selection-background-color: #2f60b3;
        }
    """)
    table.show()
    app.exec_()

I want to put the score column in ascending order, the score contains the maximum number of lines in the txt files.

I tried this:

table.sortItems(1,Qt.AscendingOrder)

It's not working and I also try this:

table.setItem(i, 1, QTableWidgetItem(str(int(max_line_number))))
table.sortItems(1,Qt.AscendingOrder)

Same still not working, the output is:

  1. 1
  2. 1
  3. 1800
  4. 1809
  5. 2
  6. 2
  7. 4

I want this output:

  1. 1809
  2. 1800
  3. 4
  4. 2
  5. etc.

0 Answers0