Results 1 to 3 of 3

Thread: Frameless Widget move

  1. #1
    Join Date
    Sep 2014
    Posts
    94
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Frameless Widget move

    Hi,


    I am trying to move frameless widget according to screen geometry .... i want xpos constant 175 and y pos should move can anybody give some code....

  2. #2
    Join Date
    Aug 2016
    Posts
    5
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Frameless Widget move

    Do you mean you just want to spawn buttons/labels/... on the screen at will? Because then you are in luck I wasted a complete day figuring that out


    frmMain is my QMainWindow. btnExtraButton is a button i can press to add a extra button on frmMain. btnRemveAll removes them all.
    oListButton is defined by (in frmMain.h) :
    Qt Code:
    1. using namespace std;
    2. ...
    3. vector<QPushButton*> oListButton;
    4. ...
    5. private slots:
    6. void oTest();
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void frmMain::on_btnExtraButton_clicked()
    2. {
    3. QPushButton *buttonA = new QPushButton(this); //create new button, with this as parent
    4.  
    5. oListButton.insert(oListButton.end(), buttonA); // use a normal std::vector to store the button, so I can later check which button was pressed
    6.  
    7. int iXlocation = 50;
    8. int iYlocation = 50;
    9. int iHeight = 100;
    10. int iWidth = 100;
    11. buttonA->setGeometry(iXlocation , iYlocation , iHeight , iWidth ); // coordinate (0,0) is in the left upper corner. Maybe i switched height en width, you'll find out soon enough
    12.  
    13. buttonA->show(); // so you can actually see it
    14.  
    15. QObject::connect(oListButton[oListButton.size() - 1], SIGNAL(clicked()), this, SLOT(oTest())); //add the last button in the vector to a connect (just so something happened when it got pressed)
    16. }
    17.  
    18. void frmMain::on_btnRemoveAll_clicked()
    19. {
    20. for (int a = 0; oListButton.size() > a; a++)
    21. {
    22. QObject::disconnect(oListButton[a], SIGNAL(clicked()), this, SLOT(oTest()));
    23. oListButton[a]->hide();
    24. oListButton[a]->deleteLater();
    25. }
    26. oListButton.clear();
    27. }
    28.  
    29. void frmMain::oTest()
    30. {
    31. QObject* obj = sender(); //obj is now the object of the sender, which i will find in my vector with a for-loop
    32. int iTest = -1;
    33. for (int a = 0; oListButton.size() > a; a++)
    34. {
    35. if (oListButton[a] == sender())
    36. {
    37. iTest = a;
    38. }
    39. }
    40.  
    41. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Frameless Widget move

    In your "clear all" slot you can just use qDeleteAll, to delete all buttons
    Qt Code:
    1. qDeleteAll(oListButton);
    2. oListButton.clear();
    To copy to clipboard, switch view to plain text mode 

    In the oTest slot you can also cast the sender instead of looping through the container if you need the object by its actual type
    Qt Code:
    1. QPushButton *button = qobject_cast<QPushButton*>(sender());
    To copy to clipboard, switch view to plain text mode 

    If you just need the index, then I would suggest using a QVector instead of std::vector and using QVector::indexOf().

    Cheers,
    _

  4. The following user says thank you to anda_skoa for this useful post:

    Fivezero05 (11th August 2016)

Similar Threads

  1. Flickering on resizing a frameless widget
    By Carlsberg in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2012, 09:53
  2. How to make frameless widget as a window or dialog
    By ainne810329 in forum Qt Programming
    Replies: 6
    Last Post: 4th November 2011, 10:27
  3. Move Frameless Dialog
    By deepal_de in forum Qt Programming
    Replies: 7
    Last Post: 6th June 2011, 08:35
  4. How to move child widget with parent widget?
    By anupamgee in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2009, 15:23
  5. Move child widget along with the parent widget
    By sreedhar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 12:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.