2

I know how to include QSpinBox in user interface by coding.

QSpinBox *spinbox= new QSpinBox(this);

Now I am looking for such a function by which I can set the QSpinBox in a particular position in user interface by giving coordinates value of this position.

I tried a couple of functions, but now one is giving me right solution how I would like to have?

Are there any such function in Qt? Thanks in advance.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Sanakum
  • 179
  • 14

1 Answers1

0

To place a widget in a certain position you must use the move() function, keep in mind that the widget should not be contained in any layout

spinbox->move(x, y);

or:

Qpoint p(x, y);
spinbox->move(p);
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • I am using Qt 5.8.0. The `setPos()` function may not be included in this version. So, It is showing `class 'QSpinBox' has no member named 'setPos'` – Sanakum Oct 24 '17 at 18:58
  • @Sanakum Sorry, I confused, the function is move (), and update my answer. :P – eyllanesc Oct 24 '17 at 19:07
  • @Sanakum If you bother to read the feedback you receive, maybe you will find an answer to every how-to-position-something question. What part of my comment was unclear? https://stackoverflow.com/questions/46912786/how-to-set-qpixmap-in-a-specific-coordinates-of-qlabel#comment80772807_46912786 – scopchanov Oct 24 '17 at 19:43
  • @scopchanov I recommend asking the question in your question, I think it is unnecessary and unproductive to put it as a comment in my answer – eyllanesc Oct 24 '17 at 19:50
  • What about flag them both as actual duplicates? – scopchanov Oct 24 '17 at 19:52
  • @scopchanov The question that you comment according to read is how to locate a QPixmap inside a QLabel that for example I use a QImage with QPainter and redraw it, but it is very different to move a widget to a specific position. QPixmap has nothing to do with a QWidget. – eyllanesc Oct 24 '17 at 19:58
  • @scopchanov Sorry. I didn't understand your comment. Can you explain what you meant. – Sanakum Oct 24 '17 at 19:58
  • QWidget is directly inherited by 44 classes. Indirectly - who knows. Though this stays the same: http://doc.qt.io/qt-5/qwidget.html#pos-prop Got the point? – scopchanov Oct 24 '17 at 20:03