Results 1 to 3 of 3

Thread: adding QFrame around several widgets

  1. #1
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default adding QFrame around several widgets

    Hi,
    I have some widgets (see pic) and im trying to put a border around them all.
    The code below is adding the border around all the widgets individually instead of globally.
    What am I doing wrong? How to I get the result seem in the example image?

    thanks

    Qt Code:
    1. Class myFrame(QFrame):
    2. def __init__(self):
    3. super(myFrame, self).__init__()
    4.  
    5. self.setStyleSheet("border: 1px solid black")
    6. self.label = QLabel('Tracker01')
    7. self.setMinimumWidth(60)
    8. self.label.setMaximumWidth(100)
    9. self.colorSwatch = QFrame()
    10. self.colorSwatch.setFixedWidth(20)
    11. self.colorSwatch.setFixedHeight(20)
    12. self.colorSwatch.setStyleSheet("border: 1px solid black")
    13.  
    14. self.X_LineEdit = QLineEdit()
    15. self.Y_LineEdit = QLineEdit()
    16. self.Z_LineEdit = QLineEdit()
    17. self.X_LineEdit.setMaximumWidth(60)
    18. self.Y_LineEdit.setMaximumWidth(60)
    19. self.Z_LineEdit.setMaximumWidth(60)
    20.  
    21. self.X_Label = QLabel('x')
    22. self.Y_Label = QLabel('y')
    23. self.Z_Label = QLabel('z')
    24. self.X_Label.setMaximumWidth(10)
    25. self.Y_Label.setMaximumWidth(10)
    26. self.Z_Label.setMaximumWidth(10)
    27.  
    28.  
    29. self.CopyValues = QPushButton('Cp')
    30. self.CreateCard = QPushButton('Cr')
    31. self.MarkPoint = QPushButton('Mk')
    32. self.CopyValues.setMaximumWidth(30)
    33. self.CreateCard.setMaximumWidth(30)
    34. self.MarkPoint.setMaximumWidth(30)
    35.  
    36. self.layout = QHBoxLayout()
    37. self.layout.addWidget(self.label)
    38. self.layout.addWidget(self.colorSwatch)
    39. self.layout.addWidget(self.X_Label)
    40. self.layout.addWidget(self.X_LineEdit)
    41. self.layout.addWidget(self.Y_Label)
    42. self.layout.addWidget(self.Y_LineEdit)
    43. self.layout.addWidget(self.Z_Label)
    44. self.layout.addWidget(self.Z_LineEdit)
    45. self.layout.addWidget(self.CreateCard)
    46. self.layout.addWidget(self.CopyValues)
    47. self.layout.addWidget(self.MarkPoint)
    48.  
    49. self.setLayout(self.layout)
    50.  
    51.  
    52. class myPanel(QDialog):
    53. def __init__(self):
    54. super(myPanel, self).__init__()
    55.  
    56. self.masterLayout = QGridLayout()
    57. self.masterLayout.addWidget(myFrame(),0,0)
    58. self.masterLayout.addWidget(myFrame(),1,0)
    59. self.setLayout(self.masterLayout)
    To copy to clipboard, switch view to plain text mode 


    ex1.JPG
    ex2.JPG

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: adding QFrame around several widgets

    You are setting a stylesheet without any class or object selector.
    It also gets applied to the labels.

    The outer frame is your frame class, the inner rectangles are the frames of the labels.

    Cheers,
    _

  3. #3
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: adding QFrame around several widgets

    Oh..right! 😄

    Thanks!

Similar Threads

  1. Adding Widgets to QFrame
    By macmos in forum Newbie
    Replies: 1
    Last Post: 28th September 2012, 17:41
  2. Adding Widgets to a QFrame instance.
    By Shiva in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 19th October 2010, 11:18
  3. Adding click event to QFrame
    By FoleyX90 in forum Newbie
    Replies: 4
    Last Post: 17th August 2010, 18:40
  4. Adding qframe with widgets to status bar
    By binaural in forum Newbie
    Replies: 4
    Last Post: 28th May 2010, 15:14

Tags for this Thread

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.