Results 1 to 19 of 19

Thread: how resize the Qwidget objects within a window

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how resize the Qwidget objects within a window

    Qt Code:
    1. #include "widget.h"
    2. #include "ui_widget.h"\
    3. #include"day25.h"
    4.  
    5. Widget::Widget(QWidget *parent) :
    6. QWidget(parent),
    7. ui(new Ui::Widget)
    8. {
    9. ui->setupUi(this);
    10. n=ui->lineEdit->text();
    11. }
    12.  
    13. Widget::~Widget()
    14. {
    15. delete ui;
    16. }
    17.  
    18. void Widget::on_pushButton_3_clicked()
    19. {
    20. day25 *k=new day25;
    21. k->show();
    22. this->hide();
    23.  
    24. }
    25.  
    26. ////////////////////////
    27. and in day25.cpp
    28. ///////////////////////////////
    29. #include "day25.h"
    30. #include "ui_day25.h"
    31. #include"widget.h"
    32.  
    33. day25::day25(Widget *parent) :
    34. Widget(parent),
    35. ui(new Ui::day25)
    36. {
    37.  
    38. ui->setupUi(this);
    39. ui->label_2->setText(n);
    40.  
    41.  
    42. }
    43.  
    44. day25::~day25()
    45. {
    46. delete ui;
    47. }
    To copy to clipboard, switch view to plain text mode 


    i tried, i entered a value and clicked the button but 2nd page(day25)is shown with previous one's object and no value is displayed

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how resize the Qwidget objects within a window

    Just to help you figure you things, how do you expect "day25" class constructor to know about the value in you "Widget" class, you need to pass the text in the constructor parameter.

    By the the way, the way you are using the widget is not the right way to do, point to review:
    1. in "on_pushButton_3_clicked()" you create a new "day25" and show it, ok fine so far. why doe you hide this, if you hide this, I don;t see code to bring it back on screen, it is not brought back, it will lying in memory, used

    2. once you dispaly "day25" how do you go back?

    I would recommend you to go through the sample examples in the Qt documentation, try editing them and see how each change behaves, and try modifying one of the sample to beahave as you wanted. Take your time to understand.

  3. #3
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how resize the Qwidget objects within a window

    i coded like this . if this is stupid forgive me okay
    Qt Code:
    1. //////////day25.cpp
    2. #include "day25.h"
    3. #include "ui_day25.h"
    4. #include "widget.h"
    5.  
    6.  
    7. day25::day25(Widget *parent) :
    8. Widget(parent),
    9. ui(new Ui::day25)
    10. {
    11.  
    12. ui->setupUi(this);
    13. //int num=100;
    14. QString qStr = QString::number(num);
    15. ui->label_2->setText(qStr);
    16.  
    17.  
    18. }
    19.  
    20. day25::~day25()
    21. {
    22. delete ui;
    23. }
    24.  
    25. ////////////widget.cpp
    26. #include "widget.h"
    27. #include "ui_widget.h"\
    28. #include "day25.h"
    29. //#include<QString>
    30.  
    31. Widget::Widget(QWidget *parent) :
    32. QWidget(parent),
    33. ui(new Ui::Widget)
    34. {
    35. ui->setupUi(this);
    36. //QString n;
    37. //n=ui->lineEdit->text();
    38. QString str;
    39. float num;
    40. str=ui->lineEdit->text();
    41. num=str.toInt();
    42.  
    43. }
    44.  
    45. Widget::~Widget()
    46. {
    47. delete ui;
    48. }
    49.  
    50. void Widget::on_pushButton_3_clicked()
    51. {
    52. day25 *k=new day25;
    53. k->show();
    54. this->hide();
    55.  
    56.  
    57. }
    58.  
    59. //////day25.h
    60. #ifndef DAY25_H
    61. #define DAY25_H
    62.  
    63. #include <QWidget>
    64. #include "widget.h"
    65.  
    66. namespace Ui {
    67. class day25;
    68. }
    69.  
    70. class day25 : public Widget
    71. {
    72. Q_OBJECT
    73.  
    74. public:
    75. explicit day25(Widget *parent = 0);
    76. ~day25();
    77.  
    78. private:
    79. Ui::day25 *ui;
    80. };
    81.  
    82. #endif // DAY25_H
    83.  
    84. /////widget.h
    85. #ifndef WIDGET_H
    86. #define WIDGET_H
    87.  
    88. #include <QWidget>
    89.  
    90. namespace Ui {
    91. class Widget;
    92. }
    93.  
    94. class Widget : public QWidget
    95. {
    96. Q_OBJECT
    97.  
    98. public:
    99. explicit Widget(QWidget *parent = 0);
    100. ~Widget();
    101.  
    102. private:
    103. Ui::Widget *ui;
    104.  
    105. private slots:
    106. void on_pushButton_3_clicked();
    107. };
    108.  
    109. #endif // WIDGET_H
    To copy to clipboard, switch view to plain text mode 
    error:num is not declared in this scope.
    if command is removed answer is always 100
    plz help meeeeeeeeee
    Last edited by vinayaka; 25th May 2011 at 11:31. Reason: spelling corrections

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how resize the Qwidget objects within a window

    Your problems are caused by your lack of understanding of C++ or even programming in general. The fact that you have a variable "x" in some place doesn't mean that another variable called "x" in a different scope will have the same value as the other one.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: how resize the Qwidget objects within a window

    Please learn some C++ (if not all) then try Qt.

  6. #6
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how resize the Qwidget objects within a window

    ok, thanku. I will do it.

Similar Threads

  1. how to resize Qmainwindow with Qwidget ?
    By zeynepb.bil in forum Qt Programming
    Replies: 10
    Last Post: 28th September 2017, 23:48
  2. Replies: 3
    Last Post: 9th January 2010, 15:47
  3. Replies: 11
    Last Post: 25th February 2009, 17:35
  4. Resize QWidget in QMainWindow
    By aamer4yu in forum Qt Programming
    Replies: 1
    Last Post: 8th March 2007, 12:16
  5. Drawing on QWidget - strech & resize
    By kemp in forum Qt Programming
    Replies: 5
    Last Post: 22nd January 2007, 14:39

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
  •  
Qt is a trademark of The Qt Company.