How To Have Access To A QWidget in MainWindow *ui Through Another Class
-
@jsulm Okay im messing around with it now, I do notice that all of the files in my mainwindow.ui are child objects of MainWindow when i create them? Does this not mean they are automatically in MainWindow class, or can i just promote the widget to my QWidget class, but then how can I actually access and change that QWidget from that class?
@Laner107 said in How To Have Access To A QWidget in MainWindow *ui Through Another Class:
are child objects of MainWindow when i create them? Does this not mean they are automatically in MainWindow class
No, this simply means that main window is the parent.
Look, if you add a QLabel to your MainWindow you will have a member variable of type QLabel, but QLabel class is not defined inside MainWindow. So, you can define your own widgets and add them as member variables to your MainWindow or any other widget:// In mywidget.h class MyWidget : public QWidget {...}; // In mainwindow.h class MainWindow : public QMainWindow { private: MyWidget *myWidget; }
-
@Laner107 said in How To Have Access To A QWidget in MainWindow *ui Through Another Class:
are child objects of MainWindow when i create them? Does this not mean they are automatically in MainWindow class
No, this simply means that main window is the parent.
Look, if you add a QLabel to your MainWindow you will have a member variable of type QLabel, but QLabel class is not defined inside MainWindow. So, you can define your own widgets and add them as member variables to your MainWindow or any other widget:// In mywidget.h class MyWidget : public QWidget {...}; // In mainwindow.h class MainWindow : public QMainWindow { private: MyWidget *myWidget; }
@jsulm said in How To Have Access To A QWidget in MainWindow *ui Through Another Class:
MainWindow you will have a member variable of type QLabel, but QLabel class is not defined inside Ma
If I add a QLabel it shows up in the file u_mainwindow.h instead of mainwindow.h, its like the u_mainwindow is meant to setup the ui i guess, and also the object that i want to use is using an API so is called QCustomPlot *stockGraph, so to actually edit this object that is presented in the MainWindow UI i have to actually add new code in the QCustomPlot API file?
-
@jsulm said in How To Have Access To A QWidget in MainWindow *ui Through Another Class:
MainWindow you will have a member variable of type QLabel, but QLabel class is not defined inside Ma
If I add a QLabel it shows up in the file u_mainwindow.h instead of mainwindow.h, its like the u_mainwindow is meant to setup the ui i guess, and also the object that i want to use is using an API so is called QCustomPlot *stockGraph, so to actually edit this object that is presented in the MainWindow UI i have to actually add new code in the QCustomPlot API file?
@Laner107 said in How To Have Access To A QWidget in MainWindow *ui Through Another Class:
If I add a QLabel it shows up in the file u_mainwindow.h instead of mainwindow.h
It's because you're using Qt Designer. The code I provided is just an example (without using Qt Designer).
"so to actually edit this object that is presented in the MainWindow UI i have to actually add new code in the QCustomPlot API file?" - no, that would mean to rebuilt Qt modules from sources. What do you mean by "edit"? Change its state? For that you simply use its public API. Please explain better what you want to do.