2

I am having a hard time figuring out how I can include several QWidgets (created in individual scripts) into the QT Designer ui file generated from a QGIS plugin builder. These are custom widgets I would like to include in the ui file because , however, I realize I have to use the ui file from Qt designer to make it connect with the map canvas in qgis. When I generate the widgets over the ui file, one gui overlaps the other.

How do I get the QWidgets into my script instead of on top of my script to where they will be included in the ui file?

I have looked at many tutorials and I can't seem to find any with this problem.

The dialog.py file is included below where it shows how all the widgets are incorporated with the ui file:

 from PyQt4 import QtGui, uic
 from PyQt4.QtGui import *
 from PyQt4.QtCore import *

 import numpy
 import re
 import sys

 from ui_eggcode import Ui_BoxCodeDialogBase

 #Individual QWidgets to import
 import ConcSpin, ConcSpin_Ct, ProxyWidget, PoshLabel, StageSpin,     FormSpin
 import IceBox, BoxCodeWidget, PresetsWidget, BoxDiagram


 FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'egg_code_dialog_base.ui'))


 class BoxCodeDialogDialog(QtGui.QDialog, FORM_CLASS): 
    def __init__(self, parent = none):
    """Constructor."""
    #super(BoxCodeDialogDialog, self).__init__(parent)

    # The following line is just the default for a dialog box,
    # comes in from QGIS plugin designer. Do not use.
    # QtGui.QDialog.__init__(self)

    self.eggvals = IceBox.IceBox()

    eggdiagram = BoxDiagram.BoxDiagram(self.eggvals)

    tabWidget = QTabWidget()
    tabWidget.setMinimumSize(QSize(370.0, 332.0))

    presetWidget = PresetsWidget.PresetsWidget(self.eggvals,eggdiagram,parent=tabWidget)
    tabWidget.addTab(presetWidget, "&Presets")
    eggWidget = BoxCodeWidget.BoxCodeWidget(self.eggvals,eggdiagram,parent=tabWidget)
    tabWidget.addTab(eggWidget, "&Box Code")

    buttonBox = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
    self.connect(buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
    self.connect(buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
    self.setWindowTitle("Set Number Format (Modal)")

    #The following activates the ui file in QT Designer
    # Sets dialog layout correctly
    layout =QVBoxLayout()
    layout.setSizeConstraint(QLayout.SetFixedSize)
    layout.addWidget(eggdiagram)
    layout.addWidget(tabWidget)
    layout.addWidget(buttonBox)

    #The following activates the ui file in QT Designer
    self.setLayout(layout)
    self.setWindowTitle("Box Code")

    # Set up the user interface from Designer.
    # After setupUI you can access any designer object by doing
    # self.<objectname>, and you can use autoconnect slots - see
    # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
    # #widgets-and-dialogs-with-auto-connect
    # Don't use the following, use Ui_BoxCodeDialogBase()from the original
    self.setupUi(self)
    self.ui = Ui_BoxCodeDialogBase()
    # Sets dialog layout correctly


    #attribute for storing position of the dialog
    self.userPos = None
  • you can include them promoting the widget to you custom qwidget. Look for promoting classes in Qt Cleator o Qt Designer. This allow addint the custom widget directly in the UI. – Luigi Pirelli Oct 29 '15 at 13:24
  • ho sorry... probably I misunderstuood the question. – Luigi Pirelli Oct 29 '15 at 13:26
  • Thank you but to be clear, I just want to know where I should put in the QWidget files so the ui ingests it and the widgets do not overlap with the ui file " self.setupUi(self)" in the code which is created from QT Designer. – user3275006 Oct 29 '15 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.