Giter Site home page Giter Site logo

QT Designer Widget Reference about pyvistaqt HOT 3 OPEN

pyvista avatar pyvista commented on May 25, 2024
QT Designer Widget Reference

from pyvistaqt.

Comments (3)

ixjlyons avatar ixjlyons commented on May 25, 2024 2

A bit late but maybe this'll be helpful to others landing here trying to do the same thing.

This can be done with the "Promote to ..." menu when you right click on the placeholder widget. Add a promoted class like this (might be able to use a more specific base class, not sure if it matters):

image

Then Add, then Promote. Then when you load the UI, it'll have an attribute with the name you give that widget in Designer that is a QtInteractor you can re-use.

An example - assumes you at least have a QPushButton named button and a widget promoted to QtInteractor named plot:

from PyQt6 import QtWidgets, uic
import pyvista as pv


class Widget(QtWidgets.QWidget):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        uic.loadUi("example.ui", self)
        # self.plot is now a QtInteractor instance
        # self.button is a QPushButton

        self.x = 0
        self.button.clicked.connect(self.add_sphere)

    def add_sphere(self):
        mesh = pv.Sphere(center=(self.x, 0, 0))
        self.plot.add_mesh(mesh)
        self.x += 1


if __name__ == "__main__":
    app = QtWidgets.QApplication([])
    win = Widget()
    win.show()
    app.exec()
example.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>ExampleUI</class>
 <widget class="QWidget" name="ExampleUI">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
  <layout class="QVBoxLayout" name="verticalLayout">
   <item>
    <widget class="QtInteractor" name="plot" native="true"/>
   </item>
   <item>
    <widget class="QPushButton" name="button">
     <property name="text">
      <string>Add Mesh</string>
     </property>
    </widget>
   </item>
  </layout>
 </widget>
 <customwidgets>
  <customwidget>
   <class>QtInteractor</class>
   <extends>QWidget</extends>
   <header>pyvistaqt</header>
   <container>1</container>
  </customwidget>
 </customwidgets>
 <resources/>
 <connections/>
</ui>

image

from pyvistaqt.

GuillaumeFavelier avatar GuillaumeFavelier commented on May 25, 2024

Hello @zoner72 sorry for jumping in so late, did you find a solution?

I think I have an idea of you want to accomplish but I am not quite sure I understand the issue. If I understand correctly, you embed the QtInteractor in a QtDesigner UI and you want to avoid re-creating the interactor everytime you upload a dataset? 🤔

from pyvistaqt.

zoner72 avatar zoner72 commented on May 25, 2024

Hi @GuillaumeFavelier

Ha, yeah its been a wee while, not a problem though. I put this part to the side and started focussing on other parts of the code.
Your description is correct, that was/is indeed what I am after. Somehow I couldn't get it to work.

from pyvistaqt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.