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 4539832
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:00:05+00:00 2026-05-21T15:00:05+00:00

I’m attempting to add a custom dialog box to my current GUI that can

  • 0

I’m attempting to add a custom dialog box to my current GUI that can be launched for the user to set some parameters. Ideally, I would like to create the custom dialog using QtDesigner. Below is the code generated by pyuic4 from the QtDesigner ui code for the dialog box.

from PyQt4 import QtCore, QtGui

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(508, 300)
        self.buttonBox = QtGui.QDialogButtonBox(Dialog)
        self.buttonBox.setGeometry(QtCore.QRect(150, 250, 341, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.label = QtGui.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(10, 120, 181, 31))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.sl_value = QtGui.QSlider(Dialog)
        self.sl_value.setGeometry(QtCore.QRect(220, 120, 161, 31))
        self.sl_value.setOrientation(QtCore.Qt.Horizontal)
        self.sl_value.setObjectName("sl_value")
        self.ed_value = QtGui.QLineEdit(Dialog)
        self.ed_value.setGeometry(QtCore.QRect(400, 120, 41, 31))
        font = QtGui.QFont()
        font.setPointSize(16)
        self.ed_value.setFont(font)
        self.ed_value.setObjectName("ed_value")
        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))
        self.label.setText(QtGui.QApplication.translate("Dialog", "Set example value:", None, QtGui.QApplication.UnicodeUTF8))

This is saved in Sub2.py
Then, in my main python file, I add

from Sub2 import Ui_Dialog

I create a new class called StartSub2 with the following code

class StartSub2(QtGui.QDialog):
    def __init__(self,parent=None):
        QtGui.QDialog.__init__(self,parent)
        self.ui = Ui_Dialog
        self.ui.setupUi(self)

Then finally in inside my main GUI there’s a function with the following code that should launch the dialog

def exampleSubGui(self):
    dialog = StartSub2(self)
    result = dialog.exec_()

Please note that the dialog is not done. Once I resolve how to even launch it I will add signal/slot connections for the slider and edit box. Also, if I understand it correctly, I need to overload the accept() method to return the user’s input.

The first problem I run into is with the __init__ method of StartSub2. I get the following error:

TypeError: unbound method setupUi() must be called with Ui_Dialog instance as
first argument (got StartSub2 instance instead)

I’m attempting to take the same approach that the main GUI is taking which uses the following code

class StartQT4(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

But this does not complain about setupUi() getting a StartQT4 instance instead of a Ui_MainWindow instance. Can anyone explain the proper way to accomplish what I’m trying to do? Or can somebody point me to a clear example or reference? Please let me know if you need more information or clarification.

  • 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-05-21T15:00:06+00:00Added an answer on May 21, 2026 at 3:00 pm
    class StartSub2(QtGui.QDialog, Ui_Dialog):
        def __init__(self,parent=None):
            QtGui.QDialog.__init__(self,parent)
            self.setupUi(self)
    

    should resolve your first problem of getting the dialog to initialize.

    To get info back I usually add a method called something like getValues to StartSub2, i.e.

    def getValues(self):
        return somethingUseful
    

    then do

    dlg = StartSub2()
    if dlg.exec_():
        values = dlg.getValues()
        # Do stuff with values
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I have some data like this: 1 2 3 4 5 9 2 6
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,

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.