Issue
In the case I added two QLineEdits with a horizontal layout. The style of QLineEdit is set to only the top and bottom borders. But there is a gap between the top and bottom borders of the two qlabels. How can I make the top and bottom borders of the two QLineEdits together without gaps?
import sys
from PyQt4 import QtGui
class Edit(QtGui.QLineEdit):
def __init__(self, text):
super(Edit, self).__init__()
self.setText(text)
self.setFixedSize(200, 40)
self.setStyleSheet("""*{border-width: 1px;
border-style: solid;
border-color: red;
border-left:none;
border-right:none;
margin:0px;
padding:0px;
}""")
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
h = QtGui.QHBoxLayout()
a = Edit("Hello World")
b = Edit("Hello World")
h.addWidget(a)
h.addWidget(b)
h.setContentsMargins(0, 0, 0, 0)
h.addStretch(1)
self.setLayout(h)
self.setGeometry(100, 100, 500, 500)
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Solution
If I'm understanding, you want to effectively make your Edit widgets appear as one with no gap between them?
Your QHBoxLayout
has a default value for spacing that is used to add a gap between widgets. You're clearing the contentsMargins
(the margin space used around the edge of the layout) but the between-widget spacing will still be there as dictated by your current style.
Add a setSpacing(0)
to clear it:
def initUI(self):
h = QtGui.QHBoxLayout()
a = Edit("Hello World")
b = Edit("Hello World")
h.addWidget(a)
h.addWidget(b)
h.setContentsMargins(0, 0, 0, 0)
h.setSpacing(0)
h.addStretch(1)
self.setLayout(h)
self.setGeometry(100, 100, 500, 500)
self.show()
Answered By - Gary Hughes
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.