Using ui in creator defined function



  • 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);
        }
    };
    

  • Lifetime Qt Champion

    Hi,

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



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


  • Moderators

    @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.



  • @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.


  • Lifetime Qt Champion

    What do you mean by "user defined function" ?

    Developer using your library or user of your application ?



  • @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.


  • Lifetime Qt Champion

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.