Hiding buttons when designing form and stopping form starting maximized



  • Hello,

    Two questions regarding form development using QtDesigner.....

    I would like to make a button hidden when the project is first run. I know how to do this in code but would like to set it up when creating the form. I have looked on the properties list for the button but can't see hide listed (only enabled)

    Also, although my form is only small, whenever I run my program it starts maximized. I have tried changing the sizePolicy properties of the form but they don't seem to have an effect. How do I stop the form maximizing at startup?

    Thanks for any guidance,

    Jimbo



  • The property name is "visible", unfortunately it is not available in Qt Designer, as it is explicitly disabled in the Qt sources:

    @
    // from src/gui/kernel/qwidget.h:
    Q_PROPERTY(bool visible READ isVisible WRITE setVisible DESIGNABLE false)
    @

    So, you're left to hide it in your C++ code, no better advice on this, sorry.

    Regarding the maximized problem, this should normally not happen. Can you post a small, complete, compilabel example that demonstrates this?



  • Hi Volker,

    Thanks for your help.

    I'm not sure if you need all the files from my project or just the ui XML file. Here's that one:

    @<?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>AddressBook</class>
    <widget class="QWidget" name="AddressBook">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>452</width>
    <height>241</height>
    </rect>
    </property>
    <property name="sizePolicy">
    <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
    <horstretch>7</horstretch>
    <verstretch>7</verstretch>
    </sizepolicy>
    </property>
    <property name="minimumSize">
    <size>
    <width>436</width>
    <height>0</height>
    </size>
    </property>
    <property name="maximumSize">
    <size>
    <width>500</width>
    <height>500</height>
    </size>
    </property>
    <property name="windowTitle">
    <string>Address Book</string>
    </property>
    <widget class="QWidget" name="layoutWidget">
    <property name="geometry">
    <rect>
    <x>10</x>
    <y>20</y>
    <width>411</width>
    <height>152</height>
    </rect>
    </property>
    <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0">
    <widget class="QLabel" name="nameLabel">
    <property name="text">
    <string>Name:</string>
    </property>
    </widget>
    </item>
    <item row="0" column="1" colspan="2">
    <widget class="QLineEdit" name="nameLineEdit">
    <property name="readOnly">
    <bool>false</bool>
    </property>
    </widget>
    </item>
    <item row="0" column="3">
    <widget class="QPushButton" name="addPushButton">
    <property name="text">
    <string>&Add</string>
    </property>
    </widget>
    </item>
    <item row="1" column="0">
    <widget class="QLabel" name="addressLabel">
    <property name="text">
    <string>Address:</string>
    </property>
    </widget>
    </item>
    <item row="1" column="1" rowspan="2" colspan="2">
    <widget class="QTextEdit" name="addressTextEdit">
    <property name="readOnly">
    <bool>false</bool>
    </property>
    </widget>
    </item>
    <item row="1" column="3">
    <widget class="QPushButton" name="editPushButton">
    <property name="text">
    <string>&Edit</string>
    </property>
    </widget>
    </item>
    <item row="2" column="3">
    <widget class="QPushButton" name="deletePushButton">
    <property name="text">
    <string>&Delete</string>
    </property>
    </widget>
    </item>
    <item row="3" column="1">
    <widget class="QPushButton" name="previousButton">
    <property name="text">
    <string>&Previous</string>
    </property>
    </widget>
    </item>
    <item row="3" column="2">
    <widget class="QPushButton" name="nextButton">
    <property name="text">
    <string>&Next</string>
    </property>
    </widget>
    </item>
    </layout>
    </widget>
    <widget class="QPushButton" name="submitPushButton">
    <property name="geometry">
    <rect>
    <x>90</x>
    <y>200</y>
    <width>92</width>
    <height>27</height>
    </rect>
    </property>
    <property name="text">
    <string>&Submit</string>
    </property>
    </widget>
    <widget class="QPushButton" name="cancelPushButton">
    <property name="enabled">
    <bool>true</bool>
    </property>
    <property name="geometry">
    <rect>
    <x>220</x>
    <y>200</y>
    <width>92</width>
    <height>27</height>
    </rect>
    </property>
    <property name="autoFillBackground">
    <bool>false</bool>
    </property>
    <property name="text">
    <string>&Cancel</string>
    </property>
    </widget>
    </widget>
    <layoutdefault spacing="6" margin="11"/>
    <resources/>
    <connections/>
    <slots>
    <signal>addContact()</signal>
    </slots>
    </ui>
    @



  • With this standard implementation around the ui file everything works as expected:

    addressbook.h
    @

    #ifndef ADDRESSBOOK_H
    #define ADDRESSBOOK_H

    #include <QWidget>

    namespace Ui {
    class AddressBook;
    }

    class AddressBook : public QWidget
    {
    Q_OBJECT

    public:
    explicit AddressBook(QWidget *parent = 0);
    ~AddressBook();

    protected:
    void changeEvent(QEvent *e);

    private:
    Ui::AddressBook *ui;
    };

    #endif // ADDRESSBOOK_H
    @

    addressbook.cpp
    @

    #include "addressbook.h"
    #include "ui_addressbook.h"

    AddressBook::AddressBook(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::AddressBook)
    {
    ui->setupUi(this);
    }

    AddressBook::~AddressBook()
    {
    delete ui;
    }

    void AddressBook::changeEvent(QEvent *e)
    {
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
    ui->retranslateUi(this);
    break;
    default:
    break;
    }
    }
    @

    main.cpp
    @
    #include <QtGui/QApplication>
    #include "addressbook.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    AddressBook ab;
    ab.show();
    
    return a.exec&#40;&#41;;
    

    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.