Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8168973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:42:04+00:00 2026-06-06T20:42:04+00:00

All I want to do is write hello world to a QGraphicsScene in a

  • 0

All I want to do is write “hello world” to a QGraphicsScene in a QGraphicsView. What am I doing wrong? I created a QGraphicsView in Designer, and then in my __init__ I create a QGraphicsScene and add some text to it… but all I get is a black window.

import sys
from PySide import QtCore, QtGui
from PySide.QtGui import *

class MyDialog(QDialog):
    def __init__(self):
        super(MyDialog, self).__init__()
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.scene = QGraphicsScene()
        self.ui.graphicsView.setScene(self.scene)
        self.scene.setSceneRect(0,0,100,100)
        self.scene.addText('hello')


def main(argv):
    app = QApplication(sys.argv)
    myapp = MyDialog()
    myapp.show()
    app.exec_()
    sys.exit()

if __name__ == "__main__":
    main(sys.argv)

The following is the UI code from Designer:

# everything from here down was created by Designer
class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(400, 300)
        self.buttonBox = QtGui.QDialogButtonBox(Dialog)
        self.buttonBox.setGeometry(QtCore.QRect(30, 240, 341, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.graphicsView = QtGui.QGraphicsView(Dialog)
        self.graphicsView.setGeometry(QtCore.QRect(50, 30, 256, 192))
        self.graphicsView.setMouseTracking(False)
        self.graphicsView.setFrameShadow(QtGui.QFrame.Sunken)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        self.graphicsView.setForegroundBrush(brush)
        self.graphicsView.setObjectName("graphicsView")

        self.retranslateUi(Dialog)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), Dialog.accept)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), Dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))

All I get is this, with a blank black canvas:

screenshot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:42:06+00:00Added an answer on June 6, 2026 at 8:42 pm

    There are two problems…

    First, you set your Foreground brush to black in your QGraphicsView. That means all children will inherit that unless they specify otherwise.

    ui

        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        #self.graphicsView.setForegroundBrush(brush)
        self.graphicsView.setBackgroundBrush(brush)
    

    Also, since you changed the background to black, you should set your text to a color you can see. Because it will be black by default:

    main

        text = self.scene.addText('hello')
        text.setDefaultTextColor(QtGui.QColor(QtCore.Qt.red))
    

    If you don’t care about the black background and just simply want to see it work, just comment out this line in your UI (or unset the brush setting in Designer) and change nothing else:

        # self.graphicsView.setForegroundBrush(brush)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I want to read and write to a file then save all the
I want to write a function that identifies all the links on a particular
I want to write a program that automatically downloads all the csv files on
I want to write a query to select from a table all rows with
I want to log/write all Javascript errors to a text file whenever an error
Currently, I have: outByte.writeInt(0x49492a00); outByte.writeInt(0x08000000); But i want to be able to write all
Ok, I've got Zend all set up and my hello world pages working. Personally,
Hello you wonderful people, All is not right with the world! I am trying
I'm trying to write a really trivial echo webapp using wai; all I want
All I want is a one pixel black border around my white UILabel text.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.