Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Setting A Labels x and Y postion within a frame given a Horiztontal layout.

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

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 4.0k Views
  • 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 Offline
    W Offline
    webmaster.skelton
    wrote on last edited by
    #1

    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
    0
    • A Offline
      A Offline
      alexander
      wrote on last edited by
      #2

      @ 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
      0
      • W Offline
        W Offline
        webmaster.skelton
        wrote on last edited by
        #3

        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
        0
        • W Offline
          W Offline
          webmaster.skelton
          wrote on last edited by
          #4

          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
          0
          • W Offline
            W Offline
            webmaster.skelton
            wrote on last edited by
            #5

            never mind, answered my own question

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tobias.hunger
              wrote on last edited by
              #6

              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
              0
              • W Offline
                W Offline
                webmaster.skelton
                wrote on last edited by
                #7

                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
                0
                • W Offline
                  W Offline
                  webmaster.skelton
                  wrote on last edited by
                  #8

                  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
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved