[Solved] Setting A Labels x and Y postion within a frame given a Horiztontal layout.
I am relatively new to QT and I keep running into some issues that should be easily remedied. I am trying to basically create a psuedo Label Factory, in which creates a label, gives the label text, and alignment. I can not for the life of me figure out how to actually give it and x and y co-ordinate relative to the MainWindow widget. Any thoughts?
Is there a way to gain access to the ui outside of the MainWindow class? I have tried creating an accessor, inheriting the MainWindow class and moving the ui to protected, Nothing i do seems to work. I am working on a rather large project and the UI NEEDS to be abstracted out. As of now i have a functions that creates a label in another class, i then add a new widget to a function located in Mainwindow... blah blah blah. and i can get the text to render that way. But i was hoping to have UI essentially its own module and create and application manager that actually handles the classes. Any help in the right direction would be greatly appreciated.
@ QWidget *widget = new QWidget;
maybe it be useful:
That did it!!! Thank you so much, i was trying to inherit my MainWindow directly, not a private Ui. That fixed everything i was have issues with in terms of interaction. The only question i have left is to how to actually set the position of a label,button,etc. I have tried label.move(QPoint) has no affect. I can set Geometry and create a QRect, but i dont want to have to create a rect for every label i need. I just want to be able to set the x and y value and iterate that position as each new label is drawn. Any suggestions?
Wait, i Got ahead of myself. I actually had ui as public. So to fix that, i inherited Ui::MainWindow into my labelfactory, and made Ui::MainWindow *ui protected. Yet it still does not recognize that i should have access to ui. Anythoughs?
never mind, answered my own question
I do not understand your problem:
bq. Is there a way to gain access to the ui outside of the MainWindow class? [...] I am working on a rather large project and the UI NEEDS to be abstracted out.
Why do you want to provide access to the internals of the UI if you want to abstract the UI out?
bq. i was hoping to have UI essentially its own module and create and application manager that actually handles the classes.
That works out of the box: The actual UI is code generated by the ui file. The "application manager" is then called MainWindow :-)
Right i understand that but i was trying to build a set of factories that created widgets, and those widgets are handles by some kind of manager, and that manager is handled by mainwindow.cpp. This way i dont have one class with 8000 lines of code. I have seen it done that way and its not pretty. Oh i might need to add that theses widget objects need to handle rendering themselves. But i figured out how i needed to do it. Thanks
Oh and one more thing, i need to dynamically generate these widgets based upon user input.( That might help things make more sense)