[Solved] Setting A Labels x and Y postion within a frame given a Horiztontal layout.
-
wrote on 9 Nov 2010, 23:54 last edited by
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?
Question two.
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.
thanks
-
wrote on 10 Nov 2010, 08:09 last edited by
@ QWidget *widget = new QWidget;
Ui::CalculatorForm ui;
ui.setupUi(widget);
@
maybe it be useful:"http://doc.qt.nokia.com/qt-maemo-4.7/designer-using-a-ui-file.html":http://doc.qt.nokia.com/qt-maemo-4.7/designer-using-a-ui-file.html
-
wrote on 10 Nov 2010, 13:45 last edited by
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?
-
wrote on 10 Nov 2010, 14:22 last edited by
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?
-
wrote on 10 Nov 2010, 14:32 last edited by
never mind, answered my own question
-
wrote on 10 Nov 2010, 19:43 last edited by
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 :-)
-
wrote on 10 Nov 2010, 19:50 last edited by
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
-
wrote on 10 Nov 2010, 19:52 last edited by
Oh and one more thing, i need to dynamically generate these widgets based upon user input.( That might help things make more sense)
1/8