English 中文(简体)
Zar+Qt, QScroll 地区问题: 该法典有什么错误?
原标题:Python+Qt, QScrollArea problem: what s wrong with this code?

我有以下法典:


#!/usr/bin/env python

import sys
from PyQt4 import QtGui, QtCore

class SimfilePanel(QtGui.QWidget):
     This class provides the simfile panel shown on the right side of the main window.   
  def __init__(self, parent=None):
       Load song info here.   
    QtGui.QWidget.__init__(self, parent)

    ## Make widgets.
    # Pane with simfile information.
    simfileInfoPane = QtGui.QWidget()
    simfileInfoPane.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
    simfileInfoGrid = QtGui.QGridLayout()
    simfileInfoPane.setLayout(simfileInfoGrid)

    simfileInfoScrollArea = QtGui.QScrollArea()
    simfileInfoScrollArea.setWidget(simfileInfoPane)
    #if DEBUG: simfileInfoScrollArea.setBackgroundRole(QtGui.QPalette.Dark);

    # This will change
    labels = []
    textfields = []
    for i in range(0,20):
      labels.append( QtGui.QLabel("Label "+str(i)) )
      textfields.append( QtGui.QLineEdit() )
      labels[i].setBuddy(textfields[i])
      simfileInfoGrid.addWidget(labels[i], i, 0)
      simfileInfoGrid.addWidget(textfields[i], i, 1)

    ## Put widgets in a grid layout.
    mainvbox = QtGui.QVBoxLayout()
    mainvbox.addWidget(simfileInfoScrollArea)
    self.setLayout(mainvbox)


# Standalone testing
if __name__ == "__main__":
  app = QtGui.QApplication(sys.argv)
  panel = SimfilePanel()
  panel.show()
  sys.exit(app.exec_())

我可以拿到我把影像文件InfoGrid带进来的话! 如果我离开了发展区,他们就会出动,但我需要一个滚动区,因为我将在最后版本中拥有很多田地,我不想把整个窗户放在屏幕上。

你们看到我试图在模拟档案中增加一个规模政策。 信息Pane似乎没有任何影响。 本来要控制我睡觉的地区 empty空!

最佳回答

在“后/>上添加“灯”。 尤其是,你在填好<>/em>你添加的植被之后,需要打上QScrollArea.setWidget。

我不确切地知道这个问题的原因,但我确实知道,我倾向于将植被“自下而上”引入: 我在结束发言之前,加上一个子项目的所有内容,然后再把它添加到父母的布局中。 我认为,这是使情况达到最佳程度的次序,但我对此可能是错误的。

下面的法典是一份拼凑文件,主要使你能够看到一线变化的发生地。

    diff -u 1848547.py  tmp2.py
--- 1848547.py  2009-12-04 11:19:09.000000000 -0800
+++ tmp2.py 2009-12-04 11:34:58.000000000 -0800
@@ -19,7 +19,6 @@
     simfileInfoPane.setLayout(simfileInfoGrid)

     simfileInfoScrollArea = QtGui.QScrollArea()
-    simfileInfoScrollArea.setWidget(simfileInfoPane)
     #if DEBUG: 
     simfileInfoScrollArea.setBackgroundRole(QtGui.QPalette.Dark)

@@ -33,6 +32,8 @@
       simfileInfoGrid.addWidget(labels[i], i, 0)
       simfileInfoGrid.addWidget(textfields[i], i, 1)

+    simfileInfoScrollArea.setWidget(simfileInfoPane)
+
     ## Put widgets in a grid layout.
     mainvbox = QtGui.QVBoxLayout()
     mainvbox.addWidget(simfileInfoScrollArea)
问题回答

我最近一直在同一件事作斗争,我认为我已经找到了你所寻求的解决办法。

问题似乎是,当你给养区增加一个空洞的植被时,其尺寸为零零(因为其中没有任何东西)。

之所以如此,是因为有一个旗帜叫。 页: 1

通过简单地打上“<条码>、可恢复植被(True),随着新项目的增加,植被就会更大。

我希望这一帮助。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签