Answer the question
In order to leave comments, you need to log in
Why does markup fail and how to fix it?
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.Qt import *
import sys, os
class tagsGUI(object):
def __init__(self):
super(tagsGUI, self).__init__()
self.title = 'tags'
self.size = (850, 500, 25)
self.start_win()
def start_win(self):
self.app = QtWidgets.QApplication(sys.argv)
self.des = self.app.desktop().screenGeometry()
self.win = QtWidgets.QWidget()
self.win.setWindowTitle(self.title)
self.win.setMinimumSize(self.size[0], self.size[1])
self.win.move((self.des.width() - self.size[0]) // 2, self.size[2])
self.pelt_window_box = QtWidgets.QVBoxLayout()
self.pelt_window_box.setContentsMargins(0, 0, 0, -2)
self.building_tags_window()
self.win.setLayout(self.pelt_window_box)
self.win.show()
sys.exit(self.app.exec_())
def building_tags_window(self):
self.TAGS_WIDGET = dict()
list_tags = list()
for _ in range(20):list_tags.append(['2018_11.31.', 'тег', '#000000', 'описание'])
self.TAGS_WIDGET['layout_box'] = QtWidgets.QVBoxLayout()
for i, tag in zip(range(len(list_tags)), list_tags):
str_tags = 'str_tag_{}'.format(i)
date = 'date_{}'.format(i)
name_tag = 'name_tag_{}'.format(i)
color_tag = 'color_tag_{}'.format(i)
descrip = 'description_{}'.format(i)
self.TAGS_WIDGET[str_tags] = QtWidgets.QHBoxLayout()
self.TAGS_WIDGET[date] = QtWidgets.QLabel(tag[0])
self.TAGS_WIDGET[name_tag] = QtWidgets.QLineEdit(tag[1])
self.TAGS_WIDGET[color_tag] = QtWidgets.QLineEdit(tag[2])
self.TAGS_WIDGET[descrip] = QtWidgets.QTextEdit(tag[3])
self.TAGS_WIDGET[str_tags].addStretch(5)
self.TAGS_WIDGET[str_tags].addWidget(self.TAGS_WIDGET[date], 0, QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
self.TAGS_WIDGET[str_tags].addWidget(self.TAGS_WIDGET[name_tag], 0, QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
self.TAGS_WIDGET[str_tags].addWidget(self.TAGS_WIDGET[color_tag], 0, QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
self.TAGS_WIDGET[str_tags].addWidget(self.TAGS_WIDGET[descrip], 100, QtCore.Qt.AlignRight | QtCore.Qt.AlignTop)
self.TAGS_WIDGET[str_tags].addStretch(5)
self.TAGS_WIDGET['layout_box'].addLayout(self.TAGS_WIDGET[str_tags])
self.TAGS_WIDGET['widget'] = QtWidgets.QWidget()
self.TAGS_WIDGET['widget'].setLayout(self.TAGS_WIDGET['layout_box'])
self.TAGS_WIDGET['scroll_area'] = QtWidgets.QScrollArea()
self.TAGS_WIDGET['scroll_area'].setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.TAGS_WIDGET['scroll_area'].setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.TAGS_WIDGET['scroll_area'].setWidget(self.TAGS_WIDGET['widget'])
self.pelt_window_box.addWidget(self.TAGS_WIDGET['scroll_area'])
if __name__ == '__main__':
tagsGUI()
Answer the question
In order to leave comments, you need to log in
You need to allow resizing of elements inside the scrollArea
Then it will float too, but
UPD layouts themselves will need to be configured
Remove alignment from self.TAGS_WIDGET[descrip], it moves the widget to the edge of the layout cell and uses the minimum widget sizes
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question