Qt Forum

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

    Unsolved Get the window location of a custum QWidget

    General and Desktop
    2
    6
    1119
    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.
    • ?
      A Former User last edited by

      Hi,

      I just need to know how I can get the window location of a custum QWidget.
      I have this own widget :

      class ColorPicker : public QWidget {
      	Q_OBJECT
      public:
      	QHBoxLayout* layout;
      	ColorGradient* mainView;
      };
      
      ColorPicker::ColorPicker(QWidget *parent) : QWidget(parent) {
      	this->layout = new QHBoxLayout;
      	setLayout(this->layout);
      
      	this->mainView = new ColorGradient;
      	this->layout->addWidget(this->mainView);
      }
      
      class ColorGradient : public QWidget {
      public:
      	ColorGradient(QWidget *parent = 0);
      

      I have for my widget ColorPicker* colorpicker->pos().y() == 130
      and for colorpicker->mainView->pos().y() == 9

      I don't understand why mainView->pos() is in local space. Is it possible tu have the global position ?

      Best regards,
      Robin

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        Hi
        When a widget is a child of a other widget, its x,y are relative to parent.
        You can use
        http://doc.qt.io/qt-5.5/qwidget.html#mapToGlobal
        To convert the child x,y to global x,y

        Can I ask why you need this?

        1 Reply Last reply Reply Quote 2
        • ?
          A Former User last edited by A Former User

          Thanks A lots!

          I need this to repaint a HUD into a texture. But I didn't need to update the entire HUD. So I use the function grab on interest widget and I repose them at the correcte location.

          It could seen experimental. And it'is ^^

          1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion last edited by

            yes sounds slightly experimental :)
            there is also
            http://doc.qt.io/qt-5.5/qwidget.html#render
            but seems u need the real widget in new pos.

            1 Reply Last reply Reply Quote 0
            • ?
              A Former User last edited by

              Is it possible to render a widget into a FBO ?
              I think Qt make his render on CPU.

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @Guest last edited by

                @Robinsondesbois
                Im not good with opengl but it think its possible
                http://stackoverflow.com/questions/7178186/how-to-draw-qglframebufferobject-onto-the-painter-from-within-qgraphicsitempai

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post