Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    [Solved] Setting A Labels x and Y postion within a frame given a Horiztontal layout.

    General and Desktop
    3
    8
    3658
    Loading More Posts
    • 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.
    • W
      webmaster.skelton 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

      1 Reply Last reply Reply Quote 0
      • A
        alexander 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

        1 Reply Last reply Reply Quote 0
        • W
          webmaster.skelton 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?

          1 Reply Last reply Reply Quote 0
          • W
            webmaster.skelton 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?

            1 Reply Last reply Reply Quote 0
            • W
              webmaster.skelton last edited by

              never mind, answered my own question

              1 Reply Last reply Reply Quote 0
              • T
                tobias.hunger 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 :-)

                1 Reply Last reply Reply Quote 0
                • W
                  webmaster.skelton 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

                  1 Reply Last reply Reply Quote 0
                  • W
                    webmaster.skelton 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 Reply Last reply Reply Quote 0
                    • First post
                      Last post