Issue
I created a custom widget using PyQt:
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QVBoxLayout, QTextEdit
class Item(QtWidgets.QWidget):
def __init__(self):
super(Item, self).__init__()
vbox = QVBoxLayout()
vbox.addWidget(QTextEdit())
self.setLayout(vbox)
Then I added this widget to a dialog:
import sys
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QApplication, QDialog, \
QTextEdit
from Item import Item
class Main(QDialog):
def __init__(self):
super(Main, self).__init__()
self.init_ui()
def init_ui(self):
vbox = QVBoxLayout()
vbox.addWidget(QTextEdit())
vbox.addWidget(Item())
self.setLayout(vbox)
def main():
app = QApplication(sys.argv)
main = Main()
main.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
The result is as follows:
As you can see, the custom widget (below) seems to have some margins to its left and right, how to remove the margin? I want the result to be like this:
Solution
Thanks to the comments of @musicamante, I added the following code to Item
and the problem was solved:
vbox.setContentsMargins(0, 0, 0, 0)
Answered By - Searene
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.