Results 1 to 1 of 1

Thread: Child widget does not get resized when main widget is.

  1. #1
    Join Date
    Sep 2010
    Posts
    28
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Child widget does not get resized when main widget is.

    I'm getting started with layouts and have some problems. I created a simple project with a QWidget as base class. I setup layouts in the ui file, and everything compiled, ran and resized fine. Then I added a base class that's supposed to keep track of multiple classes with their own ui-files. When I resize base, the widget contents doesn't follow. What am I doing wrong?

    Qt Code:
    1. // main.cpp
    2. #include <QtGui/QApplication>
    3. #include "base.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. base b;
    9. b.show();
    10.  
    11. return a.exec();
    12. }
    13.  
    14. //base.h
    15.  
    16. #ifndef BASE_H
    17. #define BASE_H
    18.  
    19. #include <QWidget>
    20.  
    21. class Widget;
    22.  
    23. class base : public QWidget
    24. {
    25. Q_OBJECT
    26. public:
    27. explicit base(QWidget *parent = 0);
    28.  
    29. signals:
    30.  
    31. public slots:
    32.  
    33. private:
    34. Widget * w;
    35. };
    36.  
    37. #endif // BASE_H
    38.  
    39. //base.cpp
    40.  
    41. #include "base.h"
    42. #include "widget.h"
    43.  
    44. base::base(QWidget *parent) :
    45. QWidget(parent),
    46. w(new Widget(this))
    47. {
    48. w->show();
    49. }
    50.  
    51. // widget.h
    52.  
    53. #ifndef WIDGET_H
    54. #define WIDGET_H
    55.  
    56. #include <QWidget>
    57.  
    58. namespace Ui {
    59. class Widget;
    60. }
    61.  
    62. class Widget : public QWidget
    63. {
    64. Q_OBJECT
    65.  
    66. public:
    67. explicit Widget(QWidget *parent = 0);
    68. ~Widget();
    69.  
    70. private:
    71. Ui::Widget *ui;
    72. };
    73.  
    74. #endif // WIDGET_H
    75.  
    76. // widget.cpp
    77.  
    78. #include "widget.h"
    79. #include "ui_widget.h"
    80.  
    81. Widget::Widget(QWidget *parent) :
    82. QWidget(parent),
    83. ui(new Ui::Widget)
    84. {
    85. ui->setupUi(this);
    86. }
    87.  
    88. Widget::~Widget()
    89. {
    90. delete ui;
    91. }
    To copy to clipboard, switch view to plain text mode 


    Added after 13 minutes:


    I solved it by using a stacked layout in base, and adding widget to that.
    Last edited by anr78; 11th November 2011 at 10:11.

Similar Threads

  1. Replies: 1
    Last Post: 23rd June 2011, 23:09
  2. Replies: 1
    Last Post: 11th March 2011, 19:34
  3. Replies: 7
    Last Post: 14th January 2010, 08:47
  4. widget not resized within QDockWidget
    By pospiech in forum Qt Programming
    Replies: 2
    Last Post: 4th December 2008, 18:19
  5. Replies: 11
    Last Post: 11th August 2008, 09:14

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.