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
Qt 6.11 is out! See what's new in the release blog

QLabel snap to ScrollBar

Scheduled Pinned Locked Moved Solved General and Desktop
47 Posts 4 Posters 10.6k 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 Mikeeeeee

    I need to bind the button to a specific area on the image. Please tell me how to do it?

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

    @Mikeeeeee Do you actually read documentation?
    https://doc.qt.io/qt-5/qwidget.html#move-1

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

    1 Reply Last reply
    1
    • mrjjM mrjj

      @Mikeeeeee
      Hi
      Its not a signal but a virtual function.
      You have to override it.

      Right clik on the class name
      alt text
      Then select
      alt text
      and you get the function

      protected:
          virtual void wheelEvent(QWheelEvent *event) override
          {
          }
      

      Then do same right click again and select
      alt text

      to move the body of function to the cpp file.

      Now you can try to implement your zoom.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #28

      @mrjj said in QLabel snap to ScrollBar:

      Right clik on the class name

      OMG, this is an option in QtC ?

      I feel so stupid now....


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

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

        Do so. But tied to a Qlabel , and not to the Image. Is it possible to link to an Image?

            QImage mapImage(":/Images/Images/mapMain.png");
            ImageViewer* myImageViewer  = new ImageViewer();
            myImageViewer->setImage(mapImage);
            ui->verticalLayout->addWidget(myImageViewer);
        
            QPushButton* btn1 = new QPushButton(myImageViewer);
            btn1->setFixedSize(20,20);
            btn1->setText("*");
            btn1->move(20,20);
        
        jsulmJ 1 Reply Last reply
        0
        • M Mikeeeeee

          Do so. But tied to a Qlabel , and not to the Image. Is it possible to link to an Image?

              QImage mapImage(":/Images/Images/mapMain.png");
              ImageViewer* myImageViewer  = new ImageViewer();
              myImageViewer->setImage(mapImage);
              ui->verticalLayout->addWidget(myImageViewer);
          
              QPushButton* btn1 = new QPushButton(myImageViewer);
              btn1->setFixedSize(20,20);
              btn1->setText("*");
              btn1->move(20,20);
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #30

          @Mikeeeeee said in QLabel snap to ScrollBar:

          QPushButton* btn1 = new QPushButton(myImageViewer);
          btn1->setFixedSize(20,20);
          btn1->setText("*");
          btn1->move(20,20);

          You forgot

          btn1->show();
          

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

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

            How do I know the visible coordinates of an Image?

            jsulmJ 1 Reply Last reply
            0
            • M Mikeeeeee

              How do I know the visible coordinates of an Image?

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

              @Mikeeeeee said in QLabel snap to ScrollBar:

              How do I know the visible coordinates of an Image?

              What do you mean?
              What are "visible coordinates" and relative to what do you want to have them?
              Do you mean you want to know which part of displayed image is visible?

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

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

                Yes. For example, I see the Central 50% of the image? How do I know I'm seeing an image from 25% to 75%?

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

                  Partially solve. But regardless of the scrollbar state, pageStep() returns a single value

                  qDebug()<<scrollArea->horizontalScrollBar()->value()
                  <<scrollArea->horizontalScrollBar()->maximum()
                  <<scrollArea->horizontalScrollBar()->minimum()
                  <<scrollArea->horizontalScrollBar()->pageStep();
                  
                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #35

                    @Mikeeeeee said in QLabel snap to ScrollBar:

                    pageStep

                    But it is a single step value. how much to scroll for a page.
                    What do you need it for ?

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

                      I wanted to know the width of the scroll and scrollbar and calculate the visible part.

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

                        Need to know the size of the scroll and its position and determine.
                        Scroll size = (widget size/picture size)/zoom

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

                          How can I remove the menu bar? If I remove createActions(); from the constructor, the program does not start.

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

                            Hi
                            If i do
                            // createActions();
                            it starts fine.
                            Please provide more details.

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

                              The compiler writes that the program closed abnormally. Debagger says he received a signal from the operating system: SIGSEGV , destination: Segmentation fault

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

                                If you want, I can send you the project

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

                                  hi
                                  I think its something else than createActions();
                                  Use the debugger to find the line where it crashes.

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

                                    error in qaction.cpp

                                    void QAction::setEnabled(bool b)
                                    {
                                        Q_D(QAction);
                                        if (b == d->enabled && b != d->forceDisabled)
                                            return;
                                        d->forceDisabled = !b;
                                        if (b && (!d->visible || (d->group && !d->group->isEnabled())))
                                            return;
                                        QAPP_CHECK("setEnabled");
                                        d->enabled = b;
                                    #ifndef QT_NO_SHORTCUT
                                        d->setShortcutEnabled(b, qApp->d_func()->shortcutMap);  //here
                                    #endif
                                        d->sendDataChanged();
                                    }
                                    
                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      Mikeeeeee
                                      wrote on last edited by
                                      #44
                                      This post is deleted!
                                      1 Reply Last reply
                                      0
                                      • M Offline
                                        M Offline
                                        Mikeeeeee
                                        wrote on last edited by Mikeeeeee
                                        #45

                                        I commented out all QAction and the program starts, but the picture at start is not loaded. But you need to change the zoom level to display the picture. Please tell me how to fix it.

                                        mrjjM 1 Reply Last reply
                                        0
                                        • M Mikeeeeee

                                          I commented out all QAction and the program starts, but the picture at start is not loaded. But you need to change the zoom level to display the picture. Please tell me how to fix it.

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

                                          @Mikeeeeee

                                          hi
                                          I think it would be better to call
                                          createActions();
                                          and simply do

                                          menuBar()->hide();

                                          so its not shown.

                                          That way you dont get issues with dangling pointers in the program.

                                          1 Reply Last reply
                                          1

                                          • Login

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