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. How to change the location of a Qwidget (code only please with how the code work)
Forum Updated to NodeBB v4.3 + New Features

How to change the location of a Qwidget (code only please with how the code work)

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 37.6k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    MathSquare
    wrote on 25 Mar 2013, 08:55 last edited by
    #1

    How to change the location of a Qwidget.
    @ui->Qwidget->y(want I want for the y core.)
    ui->Qwidget->x(want I want for the x core.)@

    but that don't work please help me i am coming from C# and what make sense to me doesn't work.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sam
      wrote on 25 Mar 2013, 09:04 last edited by
      #2

      You can use "move":http://qt-project.org/doc/qt-5.0/qtwidgets/qwidget.html#pos-prop function for your QWidget.

      eg

      @ui->yourWidget->move(50,50);@

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sierdzio
        Moderators
        wrote on 25 Mar 2013, 09:15 last edited by
        #3

        C++ does not have the concept of Properties - you need to use a setter (set*()) to change values, and getter to read them.

        Qt adds Properties, but modifying them is a bit more tedious than in C# due to language constrains.

        (Z(:^

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MathSquare
          wrote on 25 Mar 2013, 09:20 last edited by
          #4

          Doesn't work :(.
          [quote author="sierdzio" date="1364202910"]C++ does not have the concept of Properties - you need to use a setter (set*()) to change values, and getter to read them.

          Qt adds Properties, but modifying them is a bit more tedious than in C# due to language constrains.[/quote]

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MathSquare
            wrote on 25 Mar 2013, 09:24 last edited by
            #5

            Can you gice me a ex. how to do it I am a kinda of a noob to qt and c++.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 25 Mar 2013, 09:30 last edited by
              #6

              Convention in Qt is: setter beginns with "set", and getter is just the property name.

              So:
              @
              QString currentText = lineEdit->text();
              lineEdit->setText(currentString + "some changes");
              @

              Qt Properties are part of Qt Meta Object system (docs are very good, feel free to consult them):
              @
              QString currentText = lineEdit->property("text").toString();
              lineEdit->setProperty("text", currentString + "some changes");
              @

              Hope this clears things up a bit. Don't worry, you'll get it this time. I imagine transferring from C# can be a bit challenging, C++ is different even if it sometimes looks similar.

              (Z(:^

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Himanshu Rohilla
                wrote on 25 Mar 2013, 10:50 last edited by
                #7

                You can use Move function of your widget with two parameters i.e. x and y coordinates. You can also use setGeometry function of your widget with four parameters. In setGeometry function, 1st and 2nd parameters are x and y coordinates respectively and 3rd and 4th parameters are width and height of your widget.

                For example:

                ui->yourWidgetName->move(100,200);

                ui->yourWidgetName->setGeometry(100,200,400,500);

                HImanshu Rohilla

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tobias.hunger
                  wrote on 26 Mar 2013, 13:39 last edited by
                  #8

                  Usually you want to use layouts. Hardcoding positions of widgets is in 99.9% of the use-cases the wrong thing to do.

                  1 Reply Last reply
                  0

                  1/8

                  25 Mar 2013, 08:55

                  • Login

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