- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个小部件,它分为两个子小部件。一个显示图片,另一个提供编辑图片的选项。图片子部件的水平空间应是编辑子部件的 5 倍。我在网格布局中指定此约束。但是,一旦我将 QGraphicsScene(和 View )添加到编辑子小部件,该约束就会被忽略。
我尝试了几种尺寸策略,但没有一个达到我想要的效果,但我对使用这些策略没有太多经验。
class MapWidget(QWidget):
""" Widget that renders the map and displays properties """
def __init__(self, main_gui, parent=None):
super().__init__(parent=parent)
self.main_gui = main_gui
# (Re-)Build the ui
self.layout = QGridLayout()
self.setLayout(self.layout)
self.map_scene = QGraphicsScene()
self.map_scene_view = QGraphicsView()
self.map_scene_view.setViewport(QGLWidget())
self.map_scene_view.setScene(self.map_scene)
self.layout.addWidget(self.map_scene_view, 1, 1, 5, 1)
blocks_container = QVBoxLayout()
self.layout.addLayout(blocks_container, 1, 2, 1, 1)
"""
Here I add other widgets to the blocks_container,
however none of those causes problems
"""
# As soon as I also add this group, both widgets have the same size
group_blocks = QGroupBox('Blocks')
self.blocks_scene = QGraphicsScene()
self.blocks_scene_view = QGraphicsView()
self.blocks_scene_view.setViewport(QGLWidget())
self.blocks_scene_view.setScene(self.blocks_scene)
group_blocks_layout = QHBoxLayout()
group_blocks.setLayout(group_blocks_layout)
group_blocks_layout.addWidget(self.blocks_scene_view)
blocks_container.addWidget(group_blocks)
两个小部件的比例不是 5/6 和 1/6,而是共享相同的大小,这使得图片看起来很小,而编辑小部件太大。另外,一旦我删除“group_blocks”小部件,编辑子小部件就会再次具有正确的大小。因此,为了简单起见,我排除了它包含的所有其他小部件。
最佳答案
尝试并根据需要进行调整:
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtOpenGL import *
class MapWidget(QWidget):
""" Widget that renders the map and displays properties """
def __init__(self, main_gui="???", parent=None): # main_gui="???"
super().__init__(parent=parent)
self.main_gui = main_gui
# (Re-)Build the ui
self.layout = QGridLayout()
self.setLayout(self.layout)
self.map_scene = QGraphicsScene()
self.map_scene_view = QGraphicsView()
self.map_scene_view.setViewport(QGLWidget())
self.map_scene_view.setScene(self.map_scene)
# self.layout.addWidget(self.map_scene_view, 1, 1, 5, 1)
self.layout.addWidget(self.map_scene_view, 1, 1, 5, 5)
blocks_container = QVBoxLayout()
# self.layout.addLayout(blocks_container, 1, 2, 1, 1)
self.layout.addLayout(blocks_container, 1, 6, 5, 1)
self.layout.setColumnMinimumWidth(1, 320) # +++
self.layout.setRowMinimumHeight(1, 200) # +++
self.layout.setColumnStretch(1, 5) # +++
self.layout.setColumnStretch(6, 1) # +++
"""
Here I add other widgets to the blocks_container,
however none of those causes problems
"""
# As soon as I also add this group, both widgets have the same size
group_blocks = QGroupBox('Blocks')
self.blocks_scene = QGraphicsScene()
self.blocks_scene_view = QGraphicsView()
self.blocks_scene_view.setViewport(QGLWidget())
self.blocks_scene_view.setScene(self.blocks_scene)
group_blocks_layout = QHBoxLayout()
group_blocks.setLayout(group_blocks_layout)
group_blocks_layout.addWidget(self.blocks_scene_view)
blocks_container.addWidget(group_blocks)
if __name__=="__main__":
app = QApplication(sys.argv)
myapp = MapWidget()
myapp.show()
sys.exit(app.exec_())
关于python - QGraphicsScene 忽略网格布局的延伸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54051549/
我发现很多关于使用而不是关于定义 future 在 Dart 。假设我有 letsWait()这需要相当长的时间。如何使用 Future类(class)? import 'dart:async'; v
有什么区别: Class和 Class ? 谢谢 最佳答案 实际上是一样的 关于java - 反射java?延伸,我们在Stack Overflow上找到一个类似的问题: https://stacko
我想在下面的 jackson 反序列化中添加多个类。但我该怎么做呢?下面是示例代码。 XmlMapper mapper = new XmlMapper(); JaxbAnnotationModule
我正在使用 NetBeans 和 Glassfish 从现有 WSDL 构建 Web 服务。NetBeans 已从给定的 WSDL 创建了所需的类。WSDL 定义了一些基本数据类型(例如 BaseTy
我有一个获取这种类型参数的方法: NSArray 现在,当我获取此数组的一个元素时,我得到一个 ClassCastException。我的方法: public static List getWrapp
在使用泛型时,我遇到了声明 .如果我以集合接口(interface)的 addAll 方法为例。 它的声明是这样的: interface Collection { public b
我对集合中使用的通用通配符表示法有一些(违反直觉的)观察。通配符的目的 List是允许列表(T 的子类型)的赋值到“?”列表的引用的 T'。它的目的不是特别允许将 T 的子类型的元素添加到列表中( o
Closed. This question needs details or clarity。它当前不接受答案。 想改善这个问题吗?添加详细信息,并通过editing this post阐明问题。 2
你能帮我一个泛型吗?我有一个要求,我有一个 UI 表单,但根据类型,表单会完全更改。我为每种类型的表单创建了具有公共(public)字段的父 DTO 和子 DTO。使用 vaadin 进行验证。我该如
我有一个 list List generics; 我们如何对此进行排序?是否可以在 Comparator 实现上比较子类对象? 谢谢 最佳答案 参见Collections.sort ,其中T必须imp
尝试在 android 中创建一个内存游戏而不使用 xml 布局,本质上我现在想做的是在网格上的不同位置创建两张相同的卡片。所以我在这里问的是如何将这些卡片随机放置在网格上。我首先创建了随机整数数组,
所以我得到了一个接口(interface),其中我需要实现的一个方法为我提供了一个集合,并希望我将集合中的数据“全部添加”到我的对象中。我仍然不确定集合到底是什么。它是一个数组列表吗?我不相信它是,但
有没有办法强制最后一列延伸到 DataGrid WPF 的宽度? 因为在某些情况下,当 DataGrid 的宽度大于所有列的累积宽度时,DataGrid 的行为就像包含最后一个空列。 public
我在对象中有一个变量: private final Map bElementsToAdd = new HashMap<>(); 使用Builder模式中的方法我想完成这个 map 。 public B
这个问题已经有答案了: Can't add value to the Java collection with wildcard generic type (4 个回答) 已关闭 9 年前。 为什么我
我的问题正是我的标题所说的。 我有以下类(class) public class StoreItem { //Lots of irrelevant information! :) }
这个问题在这里已经有了答案: Why adding an element (of correct type) into a List through a method of is a compil
我正在准备 Java 期末考试。我遇到一道题,需要填空。 需要填空的相关代码 ____ ____ C {} ____ B extends ____ , C {} 问题是:我可以插入所有这些空白来编译我
我有一个.page 围绕着里面的所有内容。当内容延伸时,.page 也会延伸。 . 我的主要问题是 .leftBannerBackground 不使用 .page 扩展. 我能做些什么来调整 .l
有时,很多次我在文档中看到这种情况。这让我想知道要输入什么。有人可以用清晰的简化文字向我解释这句话的意思吗:D。这是怎么回事: ArrayList(Collection c) 最终被用作: new A
我是一名优秀的程序员,十分优秀!