Results 1 to 19 of 19

Thread: how resize the Qwidget objects within a window

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

    Default how resize the Qwidget objects within a window

    hai all,
    There is Qmainwindow which has 2 Qpushbuttons on the left side and Qlineedit onn the right side.I would like to get the two Qpushbuttons on the left hand side and QlineEdit resized when the QMainWindow is resized.I am novice in qt. i tried what i know but i failed. can someone help me

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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

    Get yourself familiar with the concept of "layouts".
    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.


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

    vinayaka (23rd May 2011)

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

    Default Re: how resize the Qwidget objects within a window

    hai wysota,
    i tried but failed. i tell u what it looks like .when the window was minimized the pushbutton was on the upperright hand side of the window. when it was maximized it was not on the upper right hand side of the window, on the other hand it got stick to the previous position. the right hand side was blank.

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how resize the Qwidget objects within a window

    Put your widgets into a layout or layouts. See Layout Management and Layout Examples

  6. The following user says thank you to ChrisW67 for this useful post:

    vinayaka (25th May 2011)

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

    Default Re: how resize the Qwidget objects within a window

    hai,
    i have another problem. i have a base class A and 2 derived classes B,C. In A , there is a line Edit and 2 buttons. if we click 1st button int: entered in line edit of class A must be shown in B. if we click 2nd button it should be in C's window. what should I do?can some one tell me about multiple inheritance in detail(with simple example). ( i checked it but i didnt get it)

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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

    What does your problem have to do with inheritance? Implement slots that will set values on objects and connect them to signals emitted when the buttons are clicked.
    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.


  9. The following user says thank you to wysota for this useful post:

    vinayaka (25th May 2011)

  10. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: how resize the Qwidget objects within a window

    If B and C inherit class A, the typical meaning of derived, then the question makes no sense. B is an A and C is an A. This has nothing to do with the number of windows displayed on screen or communication between them.

    I suspect you have three completely independent windows, A, B, and C, showing some widgets. You want events in A to trigger actions in B or C. You need to read about signals and slots

  11. The following user says thank you to ChrisW67 for this useful post:

    vinayaka (25th May 2011)

  12. #8
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 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

    So how is that you are using the Classes A, B, and C?
    Looks like you have objects of all the three classes in your problem, is it so? If yes, please review your design again.

    Normally you would only need Objects (instance) of B and C (as Class A is already included in both B and C)

    One important thing to note is the only objects can send signals, classes cannot send. (I agree that "class" and "object" are used almost equally in this forum replies, but it looks like from your question, you have a problem to differentiate between them)

    You said Class A is base class, and Class B & Class C are derived (I assume derived from Class A). This is not multiple inheritance, this pain single class inheritance.

    When you say Class A has QLineEdit and QPushButtons, then it is implies that Class B and Class C already have a QLineEdit & QPushButtons in them.

    Please consider re-framing your question

    http://www.cplusplus.com/doc/tutorial/inheritance/

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

    Default Re: how resize the Qwidget objects within a window

    yes , i have 3 independent windows.the integer entered in Ist window(A) must be shown in 2nd winB) when button 1 is clicked. when button 2 is clicked we must be in 3rd wiC) with int:.
    I went through some ex: but i didn't get it. Please help me(Can you teach me ,because i only started to learn cute Qt)

  14. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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

    What exactly didn't you get in the examples?
    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.


  15. The following user says thank you to wysota for this useful post:

    vinayaka (25th May 2011)

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

    Default Re: how resize the Qwidget objects within a window

    how we can inherit that intger when button is clicked?

  17. #12
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 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

    connect button's clicked() / released() signal to a slot, and in the slot read the LineEdit contents, and populate it where ever it is needed

  18. The following user says thank you to Santosh Reddy for this useful post:

    vinayaka (25th May 2011)

  19. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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

    Quote Originally Posted by vinayaka View Post
    how we can inherit that intger when button is clicked?
    Try writing some code, post it here and we'll help you fill in the blanks.
    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.


  20. #14
    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

  21. #15
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 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.

  22. #16
    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

  23. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.


  24. #18
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 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.

  25. #19
    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.