stevennathaniel

PyQt6 : Membuat Tabel Menggunakan QTableWidget

Mar 5th, 2021
731
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import mariadb
  2.  
  3. import sys
  4.  
  5. from PyQt6 import QtWidgets, QtCore, QtGui
  6.  
  7. from PyQt6.QtCore import Qt
  8.  
  9. from PyQt6.QtCore import *
  10.  
  11. from PyQt6.QtGui import *
  12.  
  13. from PyQt6.QtWidgets import QApplication, QWidget, QMessageBox, QPushButton
  14.  
  15. from PyQt6.QtWidgets import *
  16.  
  17.  
  18. aplikasi = QApplication(sys.argv)
  19.  
  20. jendela = QWidget()
  21.  
  22.  
  23. jendela.resize(800,500)
  24.  
  25.  
  26. jendela.setWindowTitle("Tabel Pegawai")
  27.  
  28. jendela.setStyleSheet(" .QWidget{Background-color: rgb(0,0,0)}")
  29.  
  30.  
  31. tabel1 = QTableWidget(jendela)
  32.  
  33. tabel1.setMinimumWidth(750)
  34.  
  35. tabel1.setMaximumHeight(300)
  36.  
  37. tabel1.verticalHeader().setVisible(False)
  38.  
  39. tabel1.setRowCount(2)
  40.  
  41. tabel1.setColumnCount(8)
  42.  
  43. tabel1.setHorizontalHeaderLabels(['Kode Unik Pegawai','Nomer Induk Pegawai','Nama Pegawai','ID Jenis Pegawai','Jenis Pegawai','Kode Bagian','Nama Bagian','Kode Jabatan'])
  44.  
  45. tabel1.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents)
  46.  
  47. tabel1.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.ResizeToContents)
  48.  
  49. tabel1.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.ResizeToContents)
  50.  
  51. tabel1.horizontalHeader().setSectionResizeMode(3, QHeaderView.ResizeMode.ResizeToContents)
  52.  
  53. tabel1.horizontalHeader().setSectionResizeMode(4, QHeaderView.ResizeMode.ResizeToContents)
  54.  
  55. tabel1.horizontalHeader().setSectionResizeMode(5, QHeaderView.ResizeMode.ResizeToContents)
  56.  
  57. tabel1.horizontalHeader().setSectionResizeMode(6, QHeaderView.ResizeMode.ResizeToContents)
  58.  
  59. tabel1.horizontalHeader().setSectionResizeMode(7, QHeaderView.ResizeMode.ResizeToContents)
  60.  
  61.  
  62.  
  63. # berhasil mengubah warna background tempat isi tabelnya:
  64.  
  65. tabel1.setStyleSheet(" .QTableWidget{Background-color: rgb(0,0,0)}")
  66.  
  67.  
  68.  
  69. # berhasil mengubah warna font di header nya menjadi warna merah
  70.  
  71. tabel1.horizontalHeader().setStyleSheet("color: red; font-size: 12pt; font-family: Arial; font-weight: bold")
  72.  
  73.  
  74. tabel1.move(10,10)
  75.  
  76.  
  77. jendela.show()
  78.  
  79. aplikasi.exec()
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×