Results 1 to 3 of 3

Thread: How to get qpushbutton to move down one row

  1. #1
    Join Date
    Sep 2017
    Posts
    12
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to get qpushbutton to move down one row

    <code>
    #include "header2.h"
    #include "ui_gui2.h"
    #include <QPushButton>
    #include <QSignalMapper>

    Classy2::Classy2(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Classy2)
    {
    ui->setupUi(this);
    }

    Classy2::~Classy2()
    {
    delete ui;
    }

    //Actions for Templates

    void Classy2:n_chronologyPushButton_pressed()
    {
    QFont font;
    font.setPointSize(10);
    font.setBold(true);

    QLabel *numberLabel=new QLabel;
    QTextEdit *chronoEdit=new QTextEdit;
    QGridLayout *chronologyGridLayout=new QGridLayout;
    QSignalMapper *signalMapper=new QSignalMapper(ui->chronologyWidget);


    numberLabel->setSizePolicy(QSizePolicy::Expanding,QSizePolicy: :Expanding);
    numberLabel->setAlignment(Qt::AlignVCenter);
    numberLabel->setFont(font);
    numberLabel->setText("3.");

    chronoEdit->setSizePolicy(QSizePolicy::Expanding,QSizePolicy: :Expanding);
    chronoEdit->setAlignment(Qt::AlignVCenter);
    chronoEdit->setFixedWidth(365);
    chronoEdit->setFixedHeight(30);


    ui->chronologyWidget->setMinimumSize(461,200);

    connect(chronologyPushButton,SIGNAL(clicked()),sig nalMapper,SLOT(move()));
    signalMapper->setMapping(chronologyPushButton,chronologyGridLay out);
    chronologyGridLayout->addWidget(chronologyPushButton,4,0,Qt::AlignVCent er);






    ui->chronologyGridLayout->addWidget(chronoEdit,2,1,Qt::AlignVCenter);
    ui->chronologyGridLayout->addWidget(numberLabel,2,0,Qt::AlignVCenter);
    ui->chronologyWidget->setLayout(ui->chronologyGridLayout);
    ui->chronologyWidget->resize(401,91);
    }
    </code>

    I have a qpushbutton inside of a qgridlayout inside of a qwidget. I am attempting to get the qpushbutton to move down one row once it's been clicked and a new label and qtextedit will be placed where the qpushbutton once was. however I ca't get the qpushbutton to move downwards. Can anybody tell me how to get the pushbutton tomove from 2,0 to 3,0 (or 4,0 from my code.) thank you

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get qpushbutton to move down one row

    Hi, instead of moving the button it might be easier to hide it on click and to show another button in the row below.

    Ginsengelf

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to get qpushbutton to move down one row

    <code>
    should be:
    [CODE]
    then it will also work.

    To your question:
    you are creating a new grid layout every time the slot gets called, with this you are not changing anything (with respect to the button) in your original layout where the button is in which is interesting, since at the end of the slot you are using the original layout for the label and text edit...
    Qt Code:
    1. void Classy2:n_chronologyPushButton_pressed()
    2. {
    3. QFont font;
    4. font.setPointSize(10);
    5. font.setBold(true);
    6.  
    7. QLabel *numberLabel=new QLabel;
    8. QTextEdit *chronoEdit=new QTextEdit;
    9. //QGridLayout *chronologyGridLayout=new QGridLayout;
    10. QSignalMapper *signalMapper=new QSignalMapper(ui->chronologyWidget);
    11.  
    12.  
    13. numberLabel->setSizePolicy(QSizePolicy::Expanding,QSizePolicy: :Expanding);
    14. numberLabel->setAlignment(Qt::AlignVCenter);
    15. numberLabel->setFont(font);
    16. numberLabel->setText("3.");
    17.  
    18. chronoEdit->setSizePolicy(QSizePolicy::Expanding,QSizePolicy: :Expanding);
    19. chronoEdit->setAlignment(Qt::AlignVCenter);
    20. chronoEdit->setFixedWidth(365);
    21. chronoEdit->setFixedHeight(30);
    22.  
    23.  
    24. ui->chronologyWidget->setMinimumSize(461,200);
    25.  
    26. connect(chronologyPushButton,SIGNAL(clicked()),sig nalMapper,SLOT(move()));
    27. signalMapper->setMapping(chronologyPushButton,chronologyGridLay out);
    28. //chronologyGridLayout->addWidget(chronologyPushButton,4,0,Qt::AlignVCent er);
    29.  
    30.  
    31. ui->chronologyGridLayout->addWidget(chronologyPushButton,4,0,Qt::AlignVCent er);
    32.  
    33. ui->chronologyGridLayout->addWidget(chronoEdit,2,1,Qt::AlignVCenter);
    34. ui->chronologyGridLayout->addWidget(numberLabel,2,0,Qt::AlignVCenter);
    35. ui->chronologyWidget->setLayout(ui->chronologyGridLayout);
    36. ui->chronologyWidget->resize(401,91);
    37. }
    To copy to clipboard, switch view to plain text mode 

    NOTE: I don't know if calling addWidget() for the button will do, or you may have to first take it out of the layout first - you need to try and see.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Problem in Move Move Event Handler.
    By redgoof in forum Qt Programming
    Replies: 0
    Last Post: 7th April 2010, 12:45
  2. Replies: 0
    Last Post: 22nd February 2010, 10:30
  3. Move the window
    By santhoshv84 in forum Qt Programming
    Replies: 3
    Last Post: 16th September 2008, 10:54
  4. Move Rectangle on mouse Move
    By vermarajeev in forum Qt Programming
    Replies: 24
    Last Post: 14th May 2007, 06:34
  5. Replies: 3
    Last Post: 26th September 2006, 13:16

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.