Results 1 to 5 of 5

Thread: why isnt my button showing?

  1. #1
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy why isnt my button showing?

    Hi,

    Im trying to create a A GUI.
    In my main, im trying to create the "QUIT" button, but it wont show when i run it. I would appreaciate if anyone would tell me why it wont show.


    Here is my code:

    #include <QApplication>
    #include <QPushButton>
    #include <QWidget>

    #include "browseimages.h"


    class MyWidget : public QWidget
    {
    public:
    MyWidget(QWidget *parent = 0);
    };

    MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
    {
    QPushButton *b_quit = new QPushButton(tr("Quit"), this);

    connect(b_quit, SIGNAL(clicked()), qApp, SLOT(b_quit()));

    }


    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);
    BrowseImages window;

    window.show();
    return app.exec();
    }
    Thank you.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why isnt my button showing?

    Where are you creating/showing an instance of MyWidget?

    Also b_quit will not look good. You could add it to a layout to handle its position and size.

  3. #3
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: why isnt my button showing?

    Thanks Marcel,

    I forgot to creat an instance of MyWidget. I fixed that, and i also used layout to handle the position and size of my quit button.

    But, my "quit" button (b_quit) isnt working. The window wont close when i press "Quit". I would like to know where is the problem.

    Here is the fixed code:

    Qt Code:
    1. #include <QApplication>
    2. #include "browseimages.h"
    3.  
    4.  
    5. #include <QPushButton>
    6. #include <QWidget>
    7. #include <QHBoxLayout>
    8. #include <QVBoxLayout>
    9. #include <Qlabel>
    10.  
    11.  
    12. class MyWidget : public QWidget
    13. {
    14. public:
    15. MyWidget(QWidget *parent = 0);
    16. };
    17.  
    18. MyWidget::MyWidget(QWidget *parent)
    19. : QWidget(parent)
    20. {
    21.  
    22. QPushButton *b_quit = new QPushButton(tr("Quit"));
    23. QPushButton *b_search = new QPushButton(tr("Search"));
    24.  
    25. connect(b_quit, SIGNAL(clicked()), qApp, SLOT(b_quit()));
    26.  
    27. b_search->setFixedHeight(40);
    28. b_quit->setFixedHeight(40);
    29.  
    30. QVBoxLayout *v_search = new QVBoxLayout;
    31. v_search->setAlignment(Qt::AlignCenter);
    32. QLabel *l_search_img = new QLabel();
    33. l_search_img->setPixmap(QPixmap("images/manual.png"));
    34. v_search->addWidget(l_search_img);
    35. v_search->addWidget(b_search);
    36.  
    37. QHBoxLayout *h_quit = new QHBoxLayout;
    38. h_quit->addStretch();
    39. h_quit->addWidget(b_quit);
    40. h_quit->addStretch();
    41.  
    42. QVBoxLayout *layout_vert = new QVBoxLayout;
    43.  
    44.  
    45. QHBoxLayout *layout_mid = new QHBoxLayout;
    46. layout_mid->addLayout(v_search);
    47.  
    48. layout_vert->addLayout(layout_mid);
    49.  
    50. layout_vert->addSpacing(30);
    51.  
    52. QHBoxLayout *h_search = new QHBoxLayout;
    53. layout_vert->addLayout(h_search);
    54. layout_vert->addLayout(h_quit);
    55.  
    56. layout_vert->addSpacing(30);
    57. this->setLayout(layout_vert);
    58. }
    59.  
    60.  
    61. int main(int argc, char **argv)
    62. {
    63. QApplication app(argc, argv);
    64. MyWidget widget;
    65.  
    66. widget.show();
    67. return app.exec();
    68. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance,
    Last edited by wysota; 7th October 2007 at 19:49. Reason: Changed [quote] into [code]

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why isnt my button showing?

    Your connect is wrong. Should be:
    Qt Code:
    1. connect(b_quit, SIGNAL(clicked()), qApp, SLOT(quit()));
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to marcel for this useful post:

    IsleWitch (7th October 2007)

  6. #5
    Join Date
    Oct 2007
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: why isnt my button showing?

    Quote Originally Posted by marcel View Post
    Your connect is wrong. Should be:
    Qt Code:
    1. connect(b_quit, SIGNAL(clicked()), qApp, SLOT(quit()));
    To copy to clipboard, switch view to plain text mode 
    Thank you what a silly mistake

Similar Threads

  1. How can I put a button onto the qLabel?
    By dwlnet in forum Qt Programming
    Replies: 3
    Last Post: 24th August 2007, 09:47
  2. Disable Checkable Button Question
    By jbpvr in forum Qt Programming
    Replies: 9
    Last Post: 20th March 2007, 17:57
  3. Mouse Over event on button
    By vishal.chauhan in forum Qt Programming
    Replies: 9
    Last Post: 10th January 2007, 05:03
  4. Button with signals and slots
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 4th December 2006, 22:24
  5. Push button double click
    By curtisw in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2006, 16:40

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.