Results 1 to 14 of 14

Thread: QWidget application does not display anything

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2013
    Location
    Hyderabad,Bangalore,India
    Posts
    70
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QWidget application does not display anything

    I have written the following program using QWidget

    and placed some pushbuttons and labels in layout and added those in another layout, but nothing is getting displayed except some default window.

    Must i have QMainwindow always as a base widget?

    please help.

    apphub.cpp
    ----------------

    Qt Code:
    1. #include "apphub.h"
    2. #include<QDebug>
    3.  
    4.  
    5. AppHub::AppHub(QWidget *parent) : QWidget(parent)
    6. {
    7. qDebug() << "AppHub";
    8.  
    9. Mainwidget = new QWidget;
    10. MainLayout = new QGridLayout;
    11. Mainwidget->setLayout(MainLayout);
    12.  
    13.  
    14. //Mainwidget->setPalette(QPalette(QColor(255,0,0,255)));
    15. //Mainwidget->setAutoFillBackground(true);
    16. Mainwidget->setMinimumSize(500,500);
    17.  
    18. for(int r=0;r<1;r++) {
    19. for(int c=0;c<2;c++) {
    20. App = new AppRsrc;
    21. MainLayout->addWidget(App,r,c,10,2,Qt::AlignTop);
    22. }
    23. }
    24. //Mainwidget->show();
    25. // showing the window seperately , but without this also it should show
    26. }
    27.  
    28. AppHub::~AppHub()
    29. {
    30.  
    31. }
    32.  
    33. AppRsrc:: AppRsrc()
    34. {
    35. qDebug() << "AppRsrc";
    36. AppWidget = new QWidget ;
    37. AppButton = new QPushButton;
    38. AppLayout = new QVBoxLayout;
    39. AppNameLbl = new QLabel;
    40. AppWidget->resize(98,97);
    41. AppWidget->setPalette(QColor(255,0,0,255));
    42. AppWidget->setAutoFillBackground(true);
    43. QPixmap pixmap(":/appimages/orca.png");
    44. QIcon AppIcon(pixmap);
    45. AppButton->setFixedSize(100,100);
    46. AppButton->setIcon(AppIcon);
    47. AppNameLbl->setFixedSize(83,20);
    48.  
    49. AppLayout->addWidget(AppButton);
    50. AppLayout->addWidget(AppNameLbl);
    51.  
    52. AppWidget->setLayout(AppLayout);
    53. }
    54.  
    55. AppRsrc:: ~AppRsrc()
    56. {
    57.  
    58. }
    To copy to clipboard, switch view to plain text mode 

    apphub.h
    ----------------

    Qt Code:
    1. #ifndef APPHUB_H
    2. #define APPHUB_H
    3.  
    4. #include <QWidget>
    5. #include <QPushButton>
    6. #include <QGridLayout>
    7. #include <QLabel>
    8. #include "app_rsrc.h"
    9.  
    10. class AppRsrc;
    11. class AppHub : public QWidget
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. AppHub(QWidget *parent = 0);
    17. ~AppHub();
    18.  
    19. private:
    20. QWidget *Mainwidget;
    21. AppRsrc *App;
    22. QGridLayout *MainLayout;
    23.  
    24. };
    25.  
    26. #endif // APPHUB_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. app_rsrc.h
    2. ----------------
    3.  
    4. #ifndef APP_RSRC_H
    5. #define APP_RSRC_H
    6.  
    7. #include<QPushButton>
    8. #include<QLabel>
    9. #include<QGridLayout>
    10. #include<QIcon>
    11. #include<QWidget>
    12.  
    13. class AppRsrc : public QWidget
    14. {
    15. private:
    16. QWidget *AppWidget;
    17. QPushButton *AppButton;
    18. QVBoxLayout *AppLayout;
    19. QLabel *AppNameLbl;
    20.  
    21. public:
    22. AppRsrc();
    23. ~AppRsrc();
    24. };
    25.  
    26. #endif // APP_RSRC_H
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    ----------------

    Qt Code:
    1. #include "apphub.h"
    2. #include <QApplication>
    3. #include<QMainWindow>
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. AppHub w;
    8.  
    9. w.show();
    10.  
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to PstdEr for this useful post:


Similar Threads

  1. Create And Display QWidget in code
    By ShapeShiftme in forum Qt Programming
    Replies: 4
    Last Post: 19th May 2012, 07:04
  2. Display an image to a plain QWidget
    By franco.amato in forum Qt Programming
    Replies: 4
    Last Post: 19th March 2012, 09:07
  3. Display a QWidget on a remote computer
    By tarod in forum Qt Programming
    Replies: 4
    Last Post: 24th July 2008, 07:41
  4. Display a QWidget on two X-Server at the same time
    By tarod in forum Qt Programming
    Replies: 0
    Last Post: 1st July 2008, 12:55
  5. Replies: 3
    Last Post: 8th March 2007, 14:54

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.