Results 1 to 8 of 8

Thread: Customize the window in windows ?

  1. #1
    Join Date
    May 2011
    Posts
    5
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Customize the window in windows ?

    Hello im good C++ developer , but i never used qt im total new in it, i wonder how to make the next setps by using codes not UI , in my image i selected the things i want done in red color , i used
    Qt Code:
    1. w.setWindowFlags(Qt::FramelessWindowHint);
    To copy to clipboard, switch view to plain text mode 
    to hide windows one

    cloud someone post me a code witch i can use QPushButton to make Close, and Mimimize buttons?



    thanks in advance


    -----------------------------------------------------------

    my next code :
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication App(argc, argv);
    4. QWidget MainWnd;
    5. QVBoxLayout Layout;
    6. QPushButton CloseBt;
    7. QPushButton MimimizeBt;
    8. // ----
    9. CloseBt.setText("X");
    10. // ----
    11. MimimizeBt.setText("_");
    12. // ----
    13. Layout.addWidget(& CloseBt, 0, Qt::AlignRight | Qt::AlignTop);
    14. Layout.addWidget(& MimimizeBt, 2, Qt::AlignRight | Qt::AlignTop);
    15. // ----
    16. MainWnd.setLayout(& Layout);
    17. MainWnd.setWindowFlags(Qt::FramelessWindowHint);
    18. MainWnd.resize(800, 600);
    19. MainWnd.show();
    20. // ----
    21. return App.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 


    does it:
    Last edited by iNewLegend; 2nd May 2011 at 13:45.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Customize the window in windows ?

    To reply strict to your question you can add this in your code:
    Qt Code:
    1. QObject::connect(&MimimizeBt, SIGNAL(clicked()), &MainWnd, SLOT(showMinimized()));
    2. QObject::connect(&CloseBt, SIGNAL(clicked()), &MainWnd, SLOT(close()));
    To copy to clipboard, switch view to plain text mode 
    And now a suggestion: use the heap for the child widgets (widgets that have a parent or will be "parented" by other widgets) - basically everything else then MainWnd.
    ***//else you can have some double-delete crash when close the application.

    LE: you can read more about signals and slots here

    ***And a correction - on a second thought: the double-delete is not the cause of the crash - but the order of the delete the meta-object will call delete for a stack allocated object causing an error (only if the parent is deleted before the child)
    Last edited by Zlatomir; 2nd May 2011 at 14:13.

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

    iNewLegend (2nd May 2011)

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

    Default Re: Customize the window in windows ?

    thanks bro , but main problem is the gui , i mean i dont know how to make it align normaly with size and be like this order , first mimmize box , then close box , extaly what i showed in the first image

  5. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Customize the window in windows ?

    Use a QHBoxLayout instead QVBoxLayout and add Minimize button first then Close.

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

    iNewLegend (2nd May 2011)

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

    Default Re: Customize the window in windows ?

    Quote Originally Posted by Zlatomir View Post
    Use a QHBoxLayout instead QVBoxLayout and add Minimize button first then Close.
    thanks bro but they dont near ...

    the close in center and mimimize in left

  8. #6
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Customize the window in windows ?

    I don't understand your problem, do you want the buttons to be smaller?

    Or the order is not right?
    Have you reversed this lines, like:
    Qt Code:
    1. QHBoxLayout Layout;
    2. //...
    3. Layout.addWidget(& MimimizeBt, 2, Qt::AlignRight | Qt::AlignTop);
    4. Layout.addWidget(& CloseBt, 0, Qt::AlignRight | Qt::AlignTop);
    To copy to clipboard, switch view to plain text mode 

    Or you can attach another print-screen so that we will see what is going on.

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

    iNewLegend (2nd May 2011)

  10. #7
    Join Date
    May 2011
    Posts
    5
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Customize the window in windows ?

    Quote Originally Posted by Zlatomir View Post
    I don't understand your problem, do you want the buttons to be smaller?

    Or the order is not right?
    Have you reversed this lines, like:
    Qt Code:
    1. QHBoxLayout Layout;
    2. //...
    3. Layout.addWidget(& MimimizeBt, 2, Qt::AlignRight | Qt::AlignTop);
    4. Layout.addWidget(& CloseBt, 0, Qt::AlignRight | Qt::AlignTop);
    To copy to clipboard, switch view to plain text mode 

    Or you can attach another print-screen so that we will see what is going on.
    never mind my code now looks like this
    Qt Code:
    1. #include <QtGui>
    2.  
    3. //--------------------------------------------------------------------------------------------------------------------------------------------
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication App(argc, argv);
    8. QWidget MainWnd;
    9. QHBoxLayout Layout;
    10. QPushButton CloseBt;
    11. QPushButton MimimizeBt;
    12. // ----
    13. CloseBt.setText("X");
    14. // ----
    15. MimimizeBt.setText("_");
    16. // ----
    17. Layout.setSpacing(1);
    18. Layout.setAlignment(Qt::AlignTop | Qt::AlignRight);
    19. Layout.addWidget(& MimimizeBt);
    20. Layout.addWidget(& CloseBt);
    21. // ----
    22. QObject::connect(& MimimizeBt, SIGNAL(clicked()), &MainWnd, SLOT(showMinimized()));
    23. QObject::connect(& CloseBt, SIGNAL(clicked()), &MainWnd, SLOT(close()));
    24.  
    25. MainWnd.setLayout(& Layout);
    26. MainWnd.setWindowFlags(Qt::FramelessWindowHint);
    27. MainWnd.resize(800, 600);
    28. MainWnd.show();
    29. // ----
    30. return App.exec();
    31. }
    32. //--------------------------------------------------------------------------------------------------------------------------------------------
    To copy to clipboard, switch view to plain text mode 

    and its looks like this:


    how can i change size of buttons? so they will be more smaller
    thanks again

  11. #8
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Customize the window in windows ?

    You can use setMaximumWidth(...)

  12. The following user says thank you to Zlatomir for this useful post:

    iNewLegend (2nd May 2011)

Similar Threads

  1. Window resize problem on Windows XP
    By smacchia in forum Qt Programming
    Replies: 1
    Last Post: 15th January 2010, 15:04
  2. qt 4.5 windows. Update window when something doing.
    By HardCore_Solder in forum Qt Programming
    Replies: 4
    Last Post: 20th May 2009, 11:59
  3. Customize Application Window
    By fruzzo in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2008, 05:20
  4. Widget without window decoration in windows
    By jiveaxe in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2008, 20:25
  5. Dock windows in a MDI window
    By aronsson in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 10:22

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.