hi new here (also this code is PySide2) . I'm trying to create a sudoku grid but my QFrame lines don't show up ( when i change the size of window some of them show up!!). i don't know how to fix this. i use the QFrame to create a separator but it doesn't work as intended.
Qt Code:
  1. import sys
  2. from PySide2.QtWidgets import *
  3.  
  4. class SudokuGrid(QWidget):
  5. def __init__(self):
  6. super(SudokuGrid, self).__init__()
  7. self.initGUI()
  8.  
  9. def initGUI(self):
  10. self.setWindowTitle("Sudoku Grid Example")
  11. self.setGeometry(800, 800, 400, 350)
  12. self.setGrid()
  13.  
  14. def setGrid(self):
  15. gridLayout = QGridLayout()
  16. box1 = QGridLayout()
  17. box2 = QGridLayout()
  18. box3 = QGridLayout()
  19. box4 = QGridLayout()
  20. box5 = QGridLayout()
  21. box6 = QGridLayout()
  22. box7 = QGridLayout()
  23. box8 = QGridLayout()
  24. box9 = QGridLayout()
  25.  
  26. hline = QFrame()
  27. hline.setFrameShape(QFrame.HLine)
  28. hline.setFrameShadow(QFrame.Sunken)
  29.  
  30. vline = QFrame()
  31. vline.setFrameShape(QFrame.VLine)
  32. vline.setFrameShadow(QFrame.Sunken)
  33.  
  34. gridLayout.addLayout(box1,0,0)
  35. gridLayout.addWidget(vline, 0, 1)
  36. gridLayout.addLayout(box2,0,2)
  37. gridLayout.addWidget(vline, 0, 3)
  38. gridLayout.addLayout(box3,0,4)
  39. gridLayout.addWidget(hline, 1, 0, 1, 3)
  40. gridLayout.addLayout(box4,2,0)
  41. gridLayout.addWidget(vline, 2, 1)
  42. gridLayout.addLayout(box5,2,2)
  43. gridLayout.addWidget(vline, 2, 3)
  44. gridLayout.addLayout(box6,2,4)
  45. gridLayout.addWidget(hline, 3, 0, 1, 3)
  46. gridLayout.addLayout(box7,4,0)
  47. gridLayout.addWidget(vline, 4, 1)
  48. gridLayout.addLayout(box8,4,2)
  49. gridLayout.addWidget(vline, 4, 3)
  50. gridLayout.addLayout(box9,4,4)
  51.  
  52. pos = [(0,0),(0,1),(0,2),
  53. (1,0),(1,1),(1,2),
  54. (2,0),(2,1),(2,2)]
  55.  
  56. i = 0
  57. while i < 9:
  58. box1.addWidget(QLabel("1"), pos[i][0], pos[i][1])
  59. box2.addWidget(QLabel("1"), pos[i][0], pos[i][1])
  60. box3.addWidget(QLabel("1"), pos[i][0], pos[i][1])
  61. box4.addWidget(QLabel("1"), pos[i][0], pos[i][1])
  62. box5.addWidget(QLabel("1"), pos[i][0], pos[i][1])
  63. box6.addWidget(QLabel("1"), pos[i][0], pos[i][1])
  64. box7.addWidget(QLabel("1"), pos[i][0], pos[i][1])
  65. box8.addWidget(QLabel("1"), pos[i][0], pos[i][1])
  66. box9.addWidget(QLabel("1"), pos[i][0], pos[i][1])
  67. i = i + 1
  68.  
  69.  
  70. self.setLayout(gridLayout)
  71.  
  72.  
  73.  
  74. if __name__ == '__main__':
  75. try:
  76. myApp = QApplication(sys.argv)
  77. myWindow = SudokuGrid()
  78. myWindow.show()
  79. myApp.exec_()
  80. sys.exit(0)
  81. except NameError:
  82. print("Name Error:", sys.exc_info()[1])
  83. except SystemExit:
  84. print("Closing Window...")
  85. except Exception:
  86. print(sys.exc_info()[1])
To copy to clipboard, switch view to plain text mode