这是一个您可以尝试的 PyQt 示例(我有 Python 中的示例,但它在 C++ 中的工作原理应该相同):
from PyQt4 import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
top = QtGui.QLabel('test', self)
bottom = QtGui.QPushButton('test', self)
splitter = QtGui.QSplitter(QtCore.Qt.Vertical)
# Try changing from False to True
splitter.setOpaqueResize(False)
splitter.addWidget(top)
splitter.addWidget(bottom)
hbox = QtGui.QHBoxLayout(self)
hbox.addWidget(splitter)
self.setLayout(hbox)
self.setGeometry(250, 200, 350, 250)
def main():
app = QtGui.QApplication([])
ex = Example()
ex.show()
app.exec_()
if __name__ == '__main__':
main()
希望这能让事情变得更清晰一些。
I am not really sure what you are asking here. It's all in the docs.
QSplitter resizes its children dynamically by default. If you would rather have QSplitter resize the children only at the end of a resize operation, call setOpaqueResize(false)
Meaning if you set setOpaqueResize(false) on your splitter, start your application and try to pull the splitter to resize the widgets it holds it will not actually resize widgets until you release the splitter. On the other hand if it is set to true it will try to resize the widgets while you are dragging the splitter handle.
It can be useful to turn this feature off if your custom widgets take long time to draw for example since it would make resizing quite slow.
But to answer your question, property opaqueResize holds whether resizing is opaque or not, i.e. will it resize the widgets while dragging the splitter or not.
Example:
Here is a PyQt example you can try (I had example laying around in Python, but it should work the same in C++):
from PyQt4 import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
top = QtGui.QLabel('test', self)
bottom = QtGui.QPushButton('test', self)
splitter = QtGui.QSplitter(QtCore.Qt.Vertical)
# Try changing from False to True
splitter.setOpaqueResize(False)
splitter.addWidget(top)
splitter.addWidget(bottom)
hbox = QtGui.QHBoxLayout(self)
hbox.addWidget(splitter)
self.setLayout(hbox)
self.setGeometry(250, 200, 350, 250)
def main():
app = QtGui.QApplication([])
ex = Example()
ex.show()
app.exec_()
if __name__ == '__main__':
main()
发布评论
评论(1)
我不太确定你在这里问什么。一切都在文档中。
意味着如果您在拆分器上设置
setOpaqueResize(false)
,启动您的应用程序并尝试拉动拆分器以调整其保存的小部件的大小,直到您释放为止,它实际上不会调整小部件的大小分离器。另一方面,如果它设置为true
,它将在您拖动拆分器手柄时尝试调整小部件的大小。例如,如果您的自定义小部件需要很长时间来绘制,则关闭此功能可能会很有用,因为它会使调整大小变得非常慢。
但要回答您的问题,属性
opaqueResize
保存调整大小是否不透明,即是否会在拖动拆分器时调整小部件的大小。示例:
这是一个您可以尝试的 PyQt 示例(我有 Python 中的示例,但它在 C++ 中的工作原理应该相同):
希望这能让事情变得更清晰一些。
I am not really sure what you are asking here. It's all in the docs.
Meaning if you set
setOpaqueResize(false)
on your splitter, start your application and try to pull the splitter to resize the widgets it holds it will not actually resize widgets until you release the splitter. On the other hand if it is set totrue
it will try to resize the widgets while you are dragging the splitter handle.It can be useful to turn this feature off if your custom widgets take long time to draw for example since it would make resizing quite slow.
But to answer your question, property
opaqueResize
holds whether resizing is opaque or not, i.e. will it resize the widgets while dragging the splitter or not.Example:
Here is a PyQt example you can try (I had example laying around in Python, but it should work the same in C++):
Hope this makes things a bit clearer.