Hi, my question is simple, I dont like how the QLayouts resize an item that is added to them, how can I avoid it?
Attachment 10140
Printable View
Hi, my question is simple, I dont like how the QLayouts resize an item that is added to them, how can I avoid it?
Attachment 10140
Maybe you should describe what you want to have?
Cheers,
-
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.
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.
Your problem definition is bit vague so here is my guess what you want.
Attachment 10151
Here is a quick and short example of how I made a QDialog based on your picture.
dialog.h:
Code:
#ifndef DIALOG_H #define DIALOG_H #include <QLineEdit> #include <QLabel> #include <QPushButton> #include <QVBoxLayout> #include <QGridLayout> #include <QSizePolicy> #include <QDialog> { Q_OBJECT public: ~Dialog(); private: QVBoxLayout *layout; QGridLayout *lineLayout; QPushButton *buton; }; #endif // DIALOG_H
dialog.cpp:
Code:
#include "dialog.h" layout->addLayout(lineLayout); 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 setLayout(layout); } Dialog::~Dialog(){ }
main.cpp
Code:
#include "dialog.h" #include <QApplication> int main(int argc, char *argv[]) { Dialog w; w.show(); return a.exec(); }
Hope this helps.
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.
Attachment 10152
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.
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.
You can also add stretch (C++) or spacers (in designer) left and right of the button.
Cheers,
_