Results 1 to 12 of 12

Thread: Avoid resize of QLayout's?

  1. #1
    Join Date
    Mar 2014
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Avoid resize of QLayout's?

    Hi, my question is simple, I dont like how the QLayouts resize an item that is added to them, how can I avoid it?

    resize.png

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Avoid resize of QLayout's?

    Maybe you should describe what you want to have?

    Cheers,
    -

  3. #3
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    256
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Avoid resize of QLayout's?

    Guessing from the picture above: (1) Set sizes of the button "fixed" and align it in the layout. (2) Put the button in a horizontal layout and add a spacer. Then put the horizontal layout in the vertical (?) layout with the text edit.

  4. #4
    Join Date
    Mar 2014
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Avoid resize of QLayout's?

    Quote Originally Posted by anda_skoa View Post
    Maybe you should...-
    I just want a normal size, not a resized one that use the whole space.

    Quote Originally Posted by Radek View Post
    Guessing from the picture....
    Is that complicated? dam, but thanks.
    Last edited by vitaR; 20th March 2014 at 02:41.

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

    Default Re: Avoid resize of QLayout's?

    It would not be complicated if you told us what you wanted. Your thread title implies that you want to "Avoid resize of QLayout", i.e not resize anything. Your picture implies you want to resize the push button. Your last post says you want a "normal size, not a resized one" without telling us what "one" refers to.

  6. #6
    Join Date
    Nov 2011
    Location
    India
    Posts
    8
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Avoid resize of QLayout's?

    Your problem definition is bit vague so here is my guess what you want.
    spacers.png

  7. #7
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Avoid resize of QLayout's?

    Here is a quick and short example of how I made a QDialog based on your picture.
    dialog.h:
    Qt Code:
    1. #ifndef DIALOG_H
    2. #define DIALOG_H
    3. #include <QLineEdit>
    4. #include <QLabel>
    5. #include <QPushButton>
    6. #include <QVBoxLayout>
    7. #include <QGridLayout>
    8. #include <QSizePolicy>
    9. #include <QDialog>
    10.  
    11. class Dialog : public QDialog
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit Dialog(QWidget *parent = 0);
    17. ~Dialog();
    18. private:
    19. QVBoxLayout *layout;
    20. QGridLayout *lineLayout;
    21. QPushButton *buton;
    22. };
    23.  
    24. #endif // DIALOG_H
    To copy to clipboard, switch view to plain text mode 

    dialog.cpp:
    Qt Code:
    1. #include "dialog.h"
    2.  
    3. Dialog::Dialog(QWidget *parent):QDialog(parent){
    4. layout=new QVBoxLayout;
    5. lineLayout=new QGridLayout;
    6. buton=new QPushButton("Ok");
    7.  
    8. lineLayout->addWidget(new QLabel("Name"),0,0);
    9. lineLayout->addWidget(new QLineEdit,0,1);
    10.  
    11. layout->addLayout(lineLayout);
    12. layout->addWidget(buton,0,Qt::AlignHCenter); //here I added it to the QVBoxLayout with stretch=0 and qt alignment...more info you can get on QVBoxLayout's page
    13. setLayout(layout);
    14. }
    15.  
    16. Dialog::~Dialog(){
    17. }
    To copy to clipboard, switch view to plain text mode 

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

    Hope this helps.
    Last edited by adutzu89; 20th March 2014 at 10:37.

  8. The following user says thank you to adutzu89 for this useful post:

    vitaR (20th March 2014)

  9. #8
    Join Date
    Mar 2014
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Avoid resize of QLayout's?

    Quote Originally Posted by adutzu89 View Post
    Here is a quick....
    Thanks this helped me.
    Sorry to everyone for the vague definition of my problem. The thing was that when I'll add a button to a layout, this button takes the whole free space of the widget.
    With this alignment this re-size of the button that the layout makes, is avoided.

    forQT.png

    There's is some other way to do this without default alignments of Qt? Just wanted to know, but my problem is solved with alignments.

  10. #9
    Join Date
    Oct 2013
    Posts
    142
    Thanks
    36
    Thanked 3 Times in 3 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Avoid resize of QLayout's?

    Other ways I can think of is that you can put the button inside another layout and use the QSizePolicy class to make the layout fixed, or inside a QDialogButtonBox.

  11. #10
    Join Date
    Mar 2014
    Posts
    27
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Avoid resize of QLayout's?

    Quote Originally Posted by adutzu89 View Post
    Other ways I can think of is that you can put the button inside another layout and use the QSizePolicy class to make the layout fixed, or inside a QDialogButtonBox.
    Thanks my friend, this works too, have a good day.

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Avoid resize of QLayout's?

    Quote Originally Posted by vitaR View Post
    I just want a normal size, not a resized one that use the whole space.
    Still not clear what you want however maybe you want to set the horizontal size policy of the button to Fixed.
    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.


  13. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Avoid resize of QLayout's?

    You can also add stretch (C++) or spacers (in designer) left and right of the button.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 29th December 2013, 19:06
  2. Replies: 3
    Last Post: 11th December 2011, 11:09
  3. Replies: 1
    Last Post: 9th May 2011, 21:45
  4. Resize QLayout w/ Mouse...or, a QWidget similar to QDockWidget
    By kiss-o-matic in forum Qt Programming
    Replies: 2
    Last Post: 24th December 2009, 11:05
  5. Replies: 2
    Last Post: 22nd January 2008, 17:10

Tags for this Thread

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.