Adding Content to pyqt4 scroll area

后端 未结 1 385
情歌与酒
情歌与酒 2021-01-17 02:37

How can I add content to a scroll area in pyqt4? DO i custom define a widget? For example, if i had a array or a lista =[10,2,2,2,22,3,3,3]. How should I displ

1条回答
  •  无人及你
    2021-01-17 03:07

    If you want to add content to a scroll area, you need to define a new widget and add that to the scroll area - like you would add a widget to a frame. For example:

    textEdit = QtGui.QTextEdit()
    scrollArea = QtGui.QScrollArea(MainWindow)
    scrollArea.setWidget(textEdit)
    

    Then, you can use textEdit.append() or textEdit.setText() to add the data in the array to the text box in the scroll area. The documentation says it all, really, albeit in C rather than python, but its obvious what you need to do:

    QLabel *imageLabel = new QLabel;
    QImage image("happyguy.png");
    imageLabel->setPixmap(QPixmap.fromImage(image));
    
    scrollArea = new QScrollArea;
    scrollArea->setBackgroundRole(QPalette.Dark);
    scrollArea->setWidget(imageLabel);
    

    0 讨论(0)
提交回复
热议问题