Results 1 to 4 of 4

Thread: How can I dynamically create a new widgets next to the other widget?

  1. #1
    Join Date
    Sep 2012
    Location
    Iran
    Posts
    34
    Thanks
    33
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default How can I dynamically create a new widgets next to the other widget?

    Hello everyone,
    I am trying to create a button which is next to a slider,or a spinbox (or any other widgets) when this button is clicked a textbox widgets would popup and user could enter his values in it (which then affects the silder)
    In order to get this done, I declared a QLineEdit object with its parent set to null, so that I can show up alone, next to the slider which it is going to change its value.
    Now I am stuck where how I am supposed to set the qlinedits location.
    Qt Code:
    1. auto loc =ui->toolButton->geometry();
    2. spinbox->setGeometry(loc.x(),loc.y(),loc.width()+10,loc.height()+10);
    3. spinbox->setWindowTitle("change your preference");
    4. ui->txtInfo->append(QString::number(loc.x())+" "+QString::number(loc.y()));
    5. spinbox->move(this->geometry().topLeft().rx()+loc.x(),this->geometry().topLeft().ry()+loc.y());
    6. spinbox->show();
    To copy to clipboard, switch view to plain text mode 
    Here I am trying to pop up a spinbox near the toolbutton,none of these work!
    I appreciate any help
    Thanks in advance

  2. #2
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How can I dynamically create a new widgets next to the other widget?

    See QStackedWidget. The widget will contain 2 pages. The first page is a placeholder (a QWidget), the second page is the QLineEdit. Initially, you will show the first page (nothing will be seen). When you click the button, you switch to the second page and the line edit will pop up. When you finish editing, you can set the slider and switch to the first page again.
    The stacked widget is in the Designer menu so that you can create the UI in the Designer.

  3. The following user says thank you to Radek for this useful post:

    Hossein (20th October 2015)

  4. #3
    Join Date
    Sep 2012
    Location
    Iran
    Posts
    34
    Thanks
    33
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How can I dynamically create a new widgets next to the other widget?

    Quote Originally Posted by Radek View Post
    See QStackedWidget. The widget will contain 2 pages. The first page is a placeholder (a QWidget), the second page is the QLineEdit. Initially, you will show the first page (nothing will be seen). When you click the button, you switch to the second page and the line edit will pop up. When you finish editing, you can set the slider and switch to the first page again.
    The stacked widget is in the Designer menu so that you can create the UI in the Designer.
    Thanks, but I'd like to find out how to get the current logic to work.
    I'd definitely give QStackedWidget a try, but before that I might not like it, it may not look well in my current GUI setup, so I am still looking how to get around the problem.
    thank you again, I appreciate your kind answer.


    Added after 1 20 minutes:


    Ok got it. here it is
    Qt Code:
    1. auto frmloc =this->geometry();
    2. auto tBtnLocation =ui->toolButton->geometry();
    3. spinbox->setWindowTitle("change your prefrence");
    4. spinbox->move(frmloc.x()+tBtnLocation.x()+150,
    5. frmloc.y()+tBtnLocation.y()+80);
    6. spinbox->show();
    7. ui->txtInfo->append(QString::number(spinbox->value()));
    To copy to clipboard, switch view to plain text mode 
    I forgot about the parents location. I had to take that into consideration and now it is done
    Last edited by Hossein; 20th October 2015 at 10:39.

  5. #4
    Join Date
    Sep 2012
    Location
    Iran
    Posts
    34
    Thanks
    33
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How can I dynamically create a new widgets next to the other widget?

    Quote Originally Posted by Hossein View Post
    Thanks, but I'd like to find out how to get the current logic to work.
    I'd definitely give QStackedWidget a try, but before that I might not like it, it may not look well in my current GUI setup, so I am still looking how to get around the problem.
    thank you again, I appreciate your kind answer.


    Added after 1 20 minutes:


    Ok got it. here it is
    Qt Code:
    1. auto frmloc =this->geometry();
    2. auto tBtnLocation =ui->toolButton->geometry();
    3. spinbox->setWindowTitle("change your prefrence");
    4. spinbox->move(frmloc.x()+tBtnLocation.x()+150,
    5. frmloc.y()+tBtnLocation.y()+80);
    6. spinbox->show();
    7. ui->txtInfo->append(QString::number(spinbox->value()));
    To copy to clipboard, switch view to plain text mode 
    I forgot about the parents location. I had to take that into consideration and now it is done
    Thats wrong, its only relative to the parent container.
    the working solution is here :
    http://www.qtcentre.org/threads/1833...et-coordinates

Similar Threads

  1. Replies: 2
    Last Post: 5th June 2012, 04:03
  2. create a new widget dynamically
    By rimie23 in forum Qt Programming
    Replies: 18
    Last Post: 24th May 2012, 14:29
  3. Create Row dynamically in QListWidget
    By sijithjames in forum Qt Programming
    Replies: 1
    Last Post: 18th July 2011, 01:02
  4. dynamically create QLabels
    By jeffmetal in forum Newbie
    Replies: 5
    Last Post: 19th June 2011, 18:24
  5. Dynamically create SVG with QWebElement
    By yawar in forum Qt Programming
    Replies: 0
    Last Post: 11th April 2010, 03:53

Tags for this Thread

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.