Important: Please read the Qt Code of Conduct -

How to move QTreeWidget realtive to "main form" ?

  • The following code is in a respose to action of button (Disolay BT devices ) in main layout.
    I like to move it relative to selected point IN THE layout - for example next to the button pushed.
    How ?

    Secondly I do not need the "full window" display - with title, min / max etc.
    Just a tree view with frame.

    Please excuse me if I am not using correct Qt terms, I am still a greehorn and obviously having problems combining Qt Designer and with plain code.

    Code :

    // print bluetooth data to tree view
    QTreeWidget *treeWidget = new QTreeWidget();
    tree process here
    move ?? relative to some point
    treeWidget->show(); // show blank form


  • Lifetime Qt Champion

    @AnneRanch What about ?
    But why do you want to position manually? Why don't you want to use layouts?
    Or do you mean you want to position/move the whole window (you can do it with move() also)?

  • @jsulm
    Mainly because I still do not understand the interaction , or lack of it, between Qt Designer and Qt Creator.
    The example I am working on puts the whole form tree (??) at random place .
    Yes, I can move it relative to desktop.
    I asked for help to move it relative to main window / form.
    In Qt terminology I need to have the tree CODE as "child" of "main window".
    Qt Designer does not let me , I need CODE designer.
    I am currently looking at QDIalog class and I think it will do what I want - in CODE.

  • To show your dialog at a specific point, you need to use mapToGlobal to retreive the position of the clicked button relative to the screen:

    connect(button,&QPushButton::clicked, [button] (bool clicked)
           QPoint xy=button->mapToGlobal(button->pos());
           xy+=QPoint(0,30);  // move down 30px
           QDialog dial;

Log in to reply