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. Label does not resize with resizeEvent

Label does not resize with resizeEvent

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.8k Views
  • 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.
  • ronyNSR Offline
    ronyNSR Offline
    ronyNS
    wrote on last edited by
    #1
    lbl = new QLabel( ui->centralWidget);
        lbl->setStyleSheet("Background-color:pink");
    

    How do i resize this label using resizeEvent . When i put this code in void Mainwindow :: resizeEvent(QreseizeEvent *evt) ; it stays the same. The size does not change.

    Please give me a proper explanation about resize event.

    Thank you.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @ronyNS said:

      resizeEvent

      http://doc.qt.io/qt-5/qwidget.html#resizeEvent

      Its called when mainwindow change size.

      To size a qlabel
      you do
      lbl->resize(x,y)
      or
      lbl->setGeometry(0,0, event->size().width(), event->size().height());
      to use the mainwindow values

      1 Reply Last reply
      1
      • ronyNSR Offline
        ronyNSR Offline
        ronyNS
        wrote on last edited by
        #3

        It fits the window size , but does not resize when i maximize the window

        My code

        Void MainWindow :: resizeEvent(QResizeEvent *event)
        {
        lbl = new QLabel (ui->centralWidget);
        Int x = MainWindow::size().height();
        Int y = MainWindow::size().width();
        lbl->resize(x,y);
        
        MainWindow::resizeEvent(evt);
        }
        
        
        
        jsulmJ 1 Reply Last reply
        0
        • ronyNSR ronyNS

          It fits the window size , but does not resize when i maximize the window

          My code

          Void MainWindow :: resizeEvent(QResizeEvent *event)
          {
          lbl = new QLabel (ui->centralWidget);
          Int x = MainWindow::size().height();
          Int y = MainWindow::size().width();
          lbl->resize(x,y);
          
          MainWindow::resizeEvent(evt);
          }
          
          
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @ronyNS Why not use a layout for that? I just tried: added a label to main window and set the layout in main window: label is resized even if I maximize window.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          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