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. How to set image fit to dialogbox in QT?
QtWS25 Last Chance

How to set image fit to dialogbox in QT?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 985 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.
  • N Offline
    N Offline
    NageswaRao
    wrote on last edited by NageswaRao
    #1

    Hi Team,I've one doubt. That is, I have a button on the main window. after clicking that button I'm able to open a dialog box and able to set an image using lable in that dialog box. What I need is, how to set that lable image fit to that dialog box. Is it possible? Thank you.

    jsulmJ 1 Reply Last reply
    0
    • N NageswaRao

      Hi Team,I've one doubt. That is, I have a button on the main window. after clicking that button I'm able to open a dialog box and able to set an image using lable in that dialog box. What I need is, how to set that lable image fit to that dialog box. Is it possible? Thank you.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @NageswaRao said in How to set image fit to dialogbox in QT?:

      how to set that lable image fit to that dialog box

      Do you have a layout in your dialog box?

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

      N 1 Reply Last reply
      2
      • jsulmJ jsulm

        @NageswaRao said in How to set image fit to dialogbox in QT?:

        how to set that lable image fit to that dialog box

        Do you have a layout in your dialog box?

        N Offline
        N Offline
        NageswaRao
        wrote on last edited by
        #3

        @jsulm I'm not having any layout in that dialog box. I'm just having a label. In that label I'm displaying an image using the following code.

        QPixmap qpm("C:/Users/user/Desktop/essentials/demo2/sample_landscape_castle_szuarin.PNG");
        ui->label_pic->setPixmap(qpm.scaled(300,300,Qt::KeepAspectRatio));

        JonBJ 1 Reply Last reply
        0
        • N NageswaRao

          @jsulm I'm not having any layout in that dialog box. I'm just having a label. In that label I'm displaying an image using the following code.

          QPixmap qpm("C:/Users/user/Desktop/essentials/demo2/sample_landscape_castle_szuarin.PNG");
          ui->label_pic->setPixmap(qpm.scaled(300,300,Qt::KeepAspectRatio));

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #4

          @NageswaRao
          You need a layout to get sizing etc. to work correctly. Try adding, say, a QVBoxLayout (dialog -> layout -> label) and then see how it is?

          1 Reply Last reply
          4
          • N Offline
            N Offline
            NageswaRao
            wrote on last edited by NageswaRao
            #5

            @JonB
            I added QVBoxLayout, like below.
            QWidget *window = new QWidget;
            QPushButton *button1 = new QPushButton("One");

            QVBoxLayout *layout = new QVBoxLayout;
            layout->addWidget(button1);
            
            window->setLayout(layout);
            window->show();
            

            The above code is working fine. It's opening one dialog box and in that it's having one button. My problem is how to add the screenshot to the label which is inside to layout.

            auto active_window = qApp->activeWindow();
            if (active_window)
            {
            QPixmap pixmap(active_window->size());
            active_window->render(&pixmap);
            ui->label_pic->setPixmap(pixmap);
            }

            JonBJ Pl45m4P 2 Replies Last reply
            0
            • N NageswaRao

              @JonB
              I added QVBoxLayout, like below.
              QWidget *window = new QWidget;
              QPushButton *button1 = new QPushButton("One");

              QVBoxLayout *layout = new QVBoxLayout;
              layout->addWidget(button1);
              
              window->setLayout(layout);
              window->show();
              

              The above code is working fine. It's opening one dialog box and in that it's having one button. My problem is how to add the screenshot to the label which is inside to layout.

              auto active_window = qApp->activeWindow();
              if (active_window)
              {
              QPixmap pixmap(active_window->size());
              active_window->render(&pixmap);
              ui->label_pic->setPixmap(pixmap);
              }

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #6

              @NageswaRao said in How to set image fit to dialogbox in QT?:

              My problem is how to add the screenshot to the label which is inside to layout.

              And what's wrong with the code you just showed? Looks OK to me.....

              1 Reply Last reply
              0
              • N NageswaRao

                @JonB
                I added QVBoxLayout, like below.
                QWidget *window = new QWidget;
                QPushButton *button1 = new QPushButton("One");

                QVBoxLayout *layout = new QVBoxLayout;
                layout->addWidget(button1);
                
                window->setLayout(layout);
                window->show();
                

                The above code is working fine. It's opening one dialog box and in that it's having one button. My problem is how to add the screenshot to the label which is inside to layout.

                auto active_window = qApp->activeWindow();
                if (active_window)
                {
                QPixmap pixmap(active_window->size());
                active_window->render(&pixmap);
                ui->label_pic->setPixmap(pixmap);
                }

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by Pl45m4
                #7

                @NageswaRao said in How to set image fit to dialogbox in QT?:

                My problem is how to add the screenshot to the label which is inside to layout.

                Your button One should take / trigger the screenshot?

                Use the QPushButton::clicked signal to call a function with your code, that takes the screenshot.


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                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