I_Stefanis | 2020-07-22 14:03:39 UTC | #1
Hello, I'm a bit confused about how I can import into my code a HistogramLUTItem() with the use of an .ui file and not directly.
mike2750 | 2020-07-23 03:13:37 UTC | #2
Can you provide an example of the minimal working example of what your trying to do and what you have done so far?
I have loaded ui files in a dialog like the below but came can be done in main.
class
class AboutDialog(QDialog):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
about_ui = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), 'ui', "about.ui")
# about_ui = QFile(":/ui/ui/about.ui")
uic.loadUi(about_ui, self)
self.about_app_logo.setPixmap(
QPixmap(os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), 'images', 'chevron_logo.png')))
# self.about_app_logo.setPixmap(QPixmap(":/forum/images/forum/images/chevron_logo.png"))
self.about_version_value.setText(version)
self.about_license_type_value.setText(license_type)
self.show()
Then in the main:
def about_dialog(self):
about_wizard = AboutDialog(self)
# about_wizard.show()
pass
Then you can dynamically load the content into from your function into a widget or whatever setup in the UI file. I do this for multiple dialogs and windows in my app. If you can provide more to work with and what you have tried im sure we can give you more specific guidance.
Purchasing Power Parity
Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]If this for the main window a basic example you can use with a mainwindow.ui file is below.
#!/usr/bin/env python3
# encoding: utf-8
from PyQt5 import uic, QtWidgets
import sys
qtCreatorFile = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "mainwindow.ui") # Type your file path
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
class build(Ui_MainWindow, QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
def start():
app = QtWidgets.QApplication(sys.argv)
bld = build()
bld.show()
sys.exit(app.exec_())
if __name__ == '__main__':
start()
I_Stefanis | 2020-07-23 14:20:53 UTC | #3
ok. thank you for your time.
let me make it more clear.
I followed the instructions of this post for including pyqtgraph widgets: https://www.pythonguis.com/courses/qt-creator/embed-pyqtgraph-custom-widgets-qt-app/
I have created a gui with the help of qt Designer. I want to include pyqtgraph widgets into my gui. The inclusion of plot widgets with statistical curves renders ok. The widgets are included with the use of an external .uic file. the name of the HistogramLut widget is "wu" and I use it with the function findChild(). My problem is that I don't know if I'm doing correctly the histogramLUT widget inclusion into the gui. I mean the step of promoting the qwidget to HistogramLUT item. I include also a snapshot of qtDesigner and also of my gui.
class MainWindow(QMainWindow, ProcessDicom): ... ... uic.loadUi('CEtb26.ui', self) ... ... self.im1 = pg.ImageItem(self.image1,levels=[0, 255]) self.histWindow = self.findChild(PlotWidget, 'wu') self.histWindow.setImageItem(self.im1)
but the only thing I get is an empty plot!
!
!
Best regards
I_Stefanis | 2020-07-24 10:55:33 UTC | #4
Finally the solution was:
Into qt Designer:
-
create a QWidget at the point where HistogramLUTWidget will appear
-
right click and promote it
-
set Promoted Class Name: HistogramLUTWidget
set Promoted Class Header: pyqtgraph.widgets.HistogramLUTWidget
4.save it
- In my code :
self.wu = pg.HistogramLUTWidget(fillHistogram=False)
everything worked!
PyQt6 Crash Course — a new tutorial in your Inbox every day
Beginner-focused crash course explaining the basics with hands-on examples.