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. QLabel snap to ScrollBar

QLabel snap to ScrollBar

Scheduled Pinned Locked Moved Solved General and Desktop
47 Posts 4 Posters 9.0k 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.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on last edited by
    #1

    Good afternoon. I have a QLabel. I asked a QLabel the picture:

    border-image: url(:/Images/Images/map Main.png) 0 0 0 0 stretch stretch;
    

    With these functions I change the size of QLabel:

    void MainWindow::on_test Button 1_clicked()
    {
            qDebug()<<ui->label Map->width()<<ui->label Map->height();
            ui->label Map->setFixedHeight(ui->label Map->height()*2);
            ui->label Map->setFixedWidth(ui->label Map->width()*2);
    }
     
    void MainWindow::on_test Button 2_clicked()
    {
            qDebug()<<ui->label Map->width()<<ui->label Map->height();
            ui->label Map->setFixedHeight(ui->label Map->height()/2);
            ui->label Map->setFixedWidth(ui->label Map->width()/2);
    }
    

    QLabel how to bind the ScrollBar to be at increased QLabel to change the zoomed area using ScrollBar. Or maybe it can be achieved in another way? In the future, you will need to make buttons on top of QLabel.Maybe you should use QML for this?

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

      Hi
      You could do as in
      https://doc.qt.io/qt-5/qtwidgets-widgets-imageviewer-example.html
      and use a ScrollArea with the label inside.
      However, this is for normal scrolling when the image is bigger than area where its
      displayed.
      It sounds a bit like you have some other sort of zoom in mind ?

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mikeeeeee
        wrote on last edited by
        #3

        Thanks.
        I included ImageViewer in the project. But how to use ImageViewer?
        I tried to create a QWidget and change the class to ImageViewer, but got an error.

        mrjjM 1 Reply Last reply
        0
        • M Mikeeeeee

          Thanks.
          I included ImageViewer in the project. But how to use ImageViewer?
          I tried to create a QWidget and change the class to ImageViewer, but got an error.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          You can just new an instance put where you want it
          ImageViewer * MyImg = new ImageViewer(this);

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mikeeeeee
            wrote on last edited by
            #5

            @mrjj said in QLabel snap to ScrollBar:

            ImageViewer * MyImg = new ImageViewer(this);

            So I get the error: no matching constructor for initialization of 'ImageViewer'

            mrjjM 1 Reply Last reply
            0
            • M Mikeeeeee

              @mrjj said in QLabel snap to ScrollBar:

              ImageViewer * MyImg = new ImageViewer(this);

              So I get the error: no matching constructor for initialization of 'ImageViewer'

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Mikeeeeee
              well its constructor is
              ImageViewer();
              so it doesn't take a parent. you change that so it can be imbedded into what you like.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mikeeeeee
                wrote on last edited by
                #7

                How to set picture? Need a method to move from private to public?

                mrjjM 1 Reply Last reply
                0
                • M Mikeeeeee

                  How to set picture? Need a method to move from private to public?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Mikeeeeee
                  hi
                  yes you can make setImage public

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mikeeeeee
                    wrote on last edited by Mikeeeeee
                    #9

                    I did so:

                        QImage mapImage(":/Images/Images/mapMain.png");
                        ImageViewer* myImageViewer  = new ImageViewer();
                        myImageViewer->setImage(mapImage);
                    

                    I have a label: ui->labelMap
                    How do I set to myImageViewer to ui->labelMap?

                    mrjjM 1 Reply Last reply
                    0
                    • M Mikeeeeee

                      I did so:

                          QImage mapImage(":/Images/Images/mapMain.png");
                          ImageViewer* myImageViewer  = new ImageViewer();
                          myImageViewer->setImage(mapImage);
                      

                      I have a label: ui->labelMap
                      How do I set to myImageViewer to ui->labelMap?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Mikeeeeee
                      You cannot put whole viewer into a Label.
                      However, you can use myImageViewer instead of
                      ui->labelMap

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        Mikeeeeee
                        wrote on last edited by
                        #11

                        But how to use? How to do this?

                        mrjjM 1 Reply Last reply
                        0
                        • M Mikeeeeee

                          But how to use? How to do this?

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @Mikeeeeee
                          well do you have ui->labelMap in layout ?
                          then just insert myImageViewer into that.

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            Mikeeeeee
                            wrote on last edited by
                            #13

                            How to do this? I created ui->label Map in the designer.

                            mrjjM 1 Reply Last reply
                            0
                            • M Mikeeeeee

                              How to do this? I created ui->label Map in the designer.

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @Mikeeeeee
                              but is it a layout?

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                Mikeeeeee
                                wrote on last edited by
                                #15

                                I appent ui->label in the ui->gridLayout_2

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  Mikeeeeee
                                  wrote on last edited by
                                  #16

                                  Also I have an empty ui->verticalLayout

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

                                    @Mikeeeeee said in QLabel snap to ScrollBar:

                                    ui->gridLayout_2

                                    ok then do
                                    ui->gridLayout_2->addWidget(myImageViewer);
                                    You can delete the label if u wish.

                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      Mikeeeeee
                                      wrote on last edited by
                                      #18

                                      Cool, works. And how to reconfigure the mouse wheel to zoom in?

                                      mrjjM 1 Reply Last reply
                                      0
                                      • M Mikeeeeee

                                        Cool, works. And how to reconfigure the mouse wheel to zoom in?

                                        mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #19

                                        @Mikeeeeee
                                        Its not a configure option. Its new code :)
                                        You can override (add) wheelEvent ( QWheelEvent * event ) to the
                                        ImageViewer class and change the size of the inner QLabel *imageLabel;
                                        to create a zoom in effect.
                                        Or create your on drawing function like here
                                        https://stackoverflow.com/questions/6650219/zooming-function-on-a-qwidget

                                        1 Reply Last reply
                                        1
                                        • M Offline
                                          M Offline
                                          Mikeeeeee
                                          wrote on last edited by
                                          #20

                                          I tried to do so, but it does not work. Please tell me how to set up the signal?

                                          connect(imageLabel, &QWidget:: wheelEvent(), this, &ImageViewer::zoomIn);
                                          
                                          mrjjM 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