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. QPushButton size.

QPushButton size.

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 10.9k 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.
  • B Offline
    B Offline
    blackbelt
    wrote on last edited by
    #1

    Hello guys, Inside a QWidget I put a Layout with two QPushButtons and a QLabel. I can change the geomtry of the QWidget that works as container for the layout but can not change the size of the QPushButton: here my code

    @void
    QTitleBar::resizeEvent( QResizeEvent * event)
    {
    QSize size = event->size();
    int widgetHeight = size.rheight();
    int widgetWidth = size.rwidth();

    std::cout << "resizeEvent h:" <<
    widgetHeight
    << " w: " << widgetWidth << std::endl;

    int layoutH = (int)((float)widgetHeight*(float)0.20);

    std::cout << "resizeEvent h:" <<
    layoutH
    << " w: " << widgetWidth << std::endl;

    mapButton->setGeometry(0, 0, 120, layoutH);
    titleWidget->setGeometry(0, 0, widgetWidth, layoutH);

    // title->setGeometry(130, 0, widgetWidth - (2130), layoutH);
    // closeButton->setGeometry(widgetWidth - (2
    130), 0, 130, layoutH);

    //closeButton->setGeometry(0, 0, widgetWidth, layoutH);

    }@

    Is there something wrong?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      amban
      wrote on last edited by
      #2

      Hi,
      If you want to change the layout according to the changing sizePolicy then use void "QWidget::adjustSize ()":http://qt-project.org/doc/qt-4.8/qwidget.html#adjustSize

      1 Reply Last reply
      0
      • B Offline
        B Offline
        blackbelt
        wrote on last edited by
        #3

        need I to override QWidget::sizeHint()?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          amban
          wrote on last edited by
          #4

          Actually if you have added the QWidgets to the layout and used widget->setLayout then when the user will change size of your widget, the elements in the layout will change size automatically. You can set -
          @
          void setMaximumHeight ( int maxh )
          void setMaximumSize ( const QSize & )
          void setMaximumSize ( int maxw, int maxh )
          void setMaximumWidth ( int maxw )
          void setMinimumHeight ( int minh )
          @
          etc....to restrict the sizes. However if you want to have a fixed defined layout then "QGroupBox":http://doc.qt.nokia.com/4.7-snapshot/qgroupbox.html and "QGridLayout":http://qt-project.org/doc/qt-4.8/QGridLayout.html will be more useful.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            blackbelt
            wrote on last edited by
            #5

            I see. If I set setMinimumSize of the QWidget "container", call QWidget::size() will return the size of the container?

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tobias.hunger
              wrote on last edited by
              #6

              Please use layouts instead of resizing widgets manually... That is just too much work and too fragile.

              So far I had to reimplement the resizeEvent once AFAIR, so if you do that regularly, then you are most likely doing something wrong (or work on a very unusual project where you might want to consider switching to QML).

              1 Reply Last reply
              0
              • B Offline
                B Offline
                blackbelt
                wrote on last edited by
                #7

                I alredy tried it in this way:

                @ titleLayout = new QHBoxLayout( this );

                titleLayout->addWidget( mapButton , Qt::AlignLeft );
                titleLayout->addWidget( title, Qt::AlignCenter );
                titleLayout->addWidget( closeButton, Qt::AlignRight);@

                change the geometry of the layout will change the geometry of its children? Could you please provide an example?

                thank you

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  amban
                  wrote on last edited by
                  #8

                  Using void QLayout::addWidget ( QWidget * w ), the layout of the elements will be from left to right (HBoxLayout) ....so just this should work fine -
                  @
                  titleLayout = new QHBoxLayout( this );

                  titleLayout->addWidget( mapButton);
                  titleLayout->addWidget( title);
                  titleLayout->addWidget( closeButton);
                  @

                  change the geometry of the layout will change the geometry of its children?
                  yes

                  I am not sure what you want to achieve. Could you please elaborate.

                  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