Results 1 to 2 of 2

Thread: how do i fix this weird bug?

  1. #1
    Join Date
    Dec 2019
    Posts
    1
    Qt products

    Default how do i fix this weird bug?

    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 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,310
    Thanks
    244
    Thanked 678 Times in 668 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: how do i fix this weird bug?

    You cannot add the same widget instance to more than one position in a layout. By repeatedly adding the same QFrame instances (hline, vline) to different positions in the gridLayout, all you are doing is moving the two instances around, not adding a copy.

    But IMO, your design is a disaster. You should seriously consider using the Qt Graphics / View architecture as the basis for your UI. You would implement your Sudoku grid as a custom QAbstractGraphicsShapeItem or maybe derive from QGraphicsRectItem with a custom paint() method to draw the interior 3x3 grids. The squares themselves could be QGraphicsSimpleTextItem instances that are children of the grid item. You would set the QGraphicsItem::ItemIsSelectable and QGraphicsItem::ItemIsFocusable flags to allow the user to click on and type into them.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. WA_QuitOnClose weird in Qt5 ?
    By drhex in forum Qt Programming
    Replies: 2
    Last Post: 24th March 2013, 17:54
  2. weird weird mingw32-make
    By KillGabio in forum Qt Programming
    Replies: 19
    Last Post: 20th January 2012, 21:09
  3. Qt Creator always weird
    By giusepped in forum Qt Programming
    Replies: 4
    Last Post: 25th July 2011, 15:59
  4. Weird bug with SQLite
    By RavenS in forum Qt Programming
    Replies: 3
    Last Post: 28th March 2009, 18:45
  5. Weird Segfault...
    By chimby in forum Qt Programming
    Replies: 3
    Last Post: 23rd January 2009, 00:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.