Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using ui in creator defined function
Forum Updated to NodeBB v4.3 + New Features

Using ui in creator defined function

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brazzoni
    wrote on last edited by Brazzoni
    #1

    I am having trouble figuring out how one can access widget from the main ui in a user defined function. Is there some way you can pass ui as a pointer or some otherwise simple way so that you can use it in a similar way to main window slots and constructors (ui->widgets->methods). I read the qt documentation, along with looking around some forums. I found the class declaration down below, however it says there is no defined function call for ui.setupUi(this). I'm not actually sure if the class would help me out in the first place, so If anyone knows a method similar to ui->widget->methods I would be very grateful.

    this was my attempt to pass it as a pointer

    drawWaves(UI::SEGYView* ui))
    {
        ui->label->setText("it worked");
    }
    

    class in Qt documentation

    class DrawWaves : public QWidget
    {
        Q_OBJECT
    
        public:
            drawWaves(QWidget *parent = 0);
        private:
            Ui::SEGYView ui;
    
        //constructor
        DrawWaves(QWidget* parent)
            :QWidget(parent)
        {
            ui.setupUi(this);
        }
    };
    
    jsulmJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What exactly are you trying to achieve with that free function ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Brazzoni
        wrote on last edited by
        #3

        SGaist I'm trying to draw a pixmap on a QGraphics View Widget/object

        1 Reply Last reply
        0
        • B Brazzoni

          I am having trouble figuring out how one can access widget from the main ui in a user defined function. Is there some way you can pass ui as a pointer or some otherwise simple way so that you can use it in a similar way to main window slots and constructors (ui->widgets->methods). I read the qt documentation, along with looking around some forums. I found the class declaration down below, however it says there is no defined function call for ui.setupUi(this). I'm not actually sure if the class would help me out in the first place, so If anyone knows a method similar to ui->widget->methods I would be very grateful.

          this was my attempt to pass it as a pointer

          drawWaves(UI::SEGYView* ui))
          {
              ui->label->setText("it worked");
          }
          

          class in Qt documentation

          class DrawWaves : public QWidget
          {
              Q_OBJECT
          
              public:
                  drawWaves(QWidget *parent = 0);
              private:
                  Ui::SEGYView ui;
          
              //constructor
              DrawWaves(QWidget* parent)
                  :QWidget(parent)
              {
                  ui.setupUi(this);
              }
          };
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Brazzoni That ui pointer and setupUI() method are created for you if you design your class in the Designer.
          To me it is still unclear what you want to do: do you want to access other UI parts from one of your UI classes? If so, then you shouldn't do this directly. Instead use signals/slots.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          B 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Brazzoni That ui pointer and setupUI() method are created for you if you design your class in the Designer.
            To me it is still unclear what you want to do: do you want to access other UI parts from one of your UI classes? If so, then you shouldn't do this directly. Instead use signals/slots.

            B Offline
            B Offline
            Brazzoni
            wrote on last edited by
            #5

            @jsulm I'm trying to find code that allows me to set scene/update the scene in QGraphics view widget from a function. So this

            ui->mywidget->method
            

            in a function that is user defined (the user defined function does not seem to know the existence of ui while slots do. I just want to call a function from a slot though to increase modularity.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              What do you mean by "user defined function" ?

              Developer using your library or user of your application ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Brazzoni
                wrote on last edited by
                #7

                @SGaist user defined as in Developer using my library/Me making a function that is called from the menu bar Open slot. Essentially my program will draw a seismic graph after the user pics a file. But I would like to make a drawWaves function so that it can be implemented in different parts of the program. But I can't use ui->GraphicsViewObjectName->addScene in a coder defined function because ui is not defined. Is it as simple as passing ui as a pointer? I've tried to do this but it doesn't seem to work.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Sounds like you should rather use a plugin based application and define a simple interface for that.

                  The developer using your product should not need to worry about where the things they should paint come from. Basically the method should e.g. receive a painter and operate on that. Otherwise it will create very tight loop that will make your application very difficult to follow and work with.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved