Disable resizing of a form

I want to disable resizing my form - here is what I have tried. I have changed the resize policy of the form to the following HorizontalPolicy:Fixed VerticalPloicy: Fixed

I have also tried the following

Form *w = new Form(); 
w->setFixedSize(w->size());
w->show();

But the form still gets resized by dragging the corners. Any suggestions ?

Answers


It definitely has to be possible.

Firstly you should know, that before window is actually shown it has no information of it's size - so size will probably return 0 (or invalid; or anything ;) ) at this point - it would probably mess up entire sizing and is therefore silently rejected. I would try

Form *w = new Form();
//w->ensurePolished();
w->setFixedSize(w->sizeHint());
w->show();

Size hint should have correct value no matter what. QWidget::ensurePolished() might be necessary here, but I recommend trying first without it - if it works, why complicate things?

If it still doesn't work, then you can simply try overriding resizeEvent() and setting the only right size for your widget if user resizes it to anything else. This will still give user an illusion of resize-ability (cursors changes on the edges and so on), so it's really the last option.

EDIT:

#include <QtGui/QApplication>
#include <QWidget>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWidget w;
    w.setFixedSize(500,500);
    w.show();
    return a.exec();
}

Result: widget cannot be resized. So it is not change to QMainWindow that helped - oat least on my system a simple widget can do it too ;)


Need Your Help

Can I cast GameKit's peerID to uint32_t

c++ objective-c gamekit uint32

I am using GameKit for networking in my C++ application (created an Objective-C class for managing GameKit networking), but the problem is that GameKit uses NSString (not a C++ type) to identify pe...

To set delay on a button click in java?

java swing concurrency timer

I have a save button in a JFrame ;on clicking save the 'save' text sets to 'saving....'; I need to set that text as 'saved' after a delay of 10 seconds.How is it possible in java?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.