Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Hiding buttons when designing form and stopping form starting maximized
Forum Updated to NodeBB v4.3 + New Features

Hiding buttons when designing form and stopping form starting maximized

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 7.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jimbo
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jimbo
        wrote on last edited by
        #3

        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>
        @

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          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;;
          

          }
          @

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved