Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Selecting Item and Scrolling ListWidget Area Problem
QtWS25 Last Chance

Selecting Item and Scrolling ListWidget Area Problem

Scheduled Pinned Locked Moved Mobile and Embedded
12 Posts 3 Posters 3.9k 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.
  • A Offline
    A Offline
    anticore
    wrote on last edited by
    #1

    Hello everybody,

    I am newbie on QT.
    I need to list some selectable items on the screen. I decided to do it with ListWidget. I defined the stylesheet as follows.
    @
    QListWidget::item
    {
    color: rgb(255, 255, 255);
    background-color: rgb(0, 0, 127);
    border-color: rgb(65, 65, 65);
    }

    QListWidget::item:selected
    {
    background-color: rgb(0, 85, 255);
    }
    @

    Everything Ok without a problem.
    I press on an item and select it. Then I move the cursor to next item without releasing the button. Previous item unselected but next item selected and so on... I do not want to select next item. Only the first pressed item should be selected if cursor on it, not others.
    Also if I move the cursor out of ListWidget area scrolling is working. I want to stop the scrolling because I am using up-down buttons to navigate pages. Scrolling is too slow on my device.

    Please help...

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

      I solved scrolling problem with

      @ listWidget->setAutoScroll(false);@

      Item selecting problem continue, please help...

      1 Reply Last reply
      0
      • T Offline
        T Offline
        t3685
        wrote on last edited by
        #3

        Hi,

        For more readability use the "@""@" tag for your code.

        As for you problem, have you tried this:

        http://qt-project.org/doc/qt-5/qabstractitemview.html#selectionMode-prop

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

          Hi,

          I have tried all of the modes, however it is not the solution or I could not.

          Thank you.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi and welcome to devnet,

            Have a look at setSelectionMode and ExtendedSelection

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • A Offline
              A Offline
              anticore
              wrote on last edited by
              #6

              Thank you sGaist,

              I tried ExtendedSelection, but I need select only one item. I want to highlight only first pressed item if cursor on it until I release mouse button.
              In other words, If I press mouse button on an item, I don't want hover effect on other items.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                What you are trying to do looks like the drag and drop functionality but without actually doing anything. It doesn't fit in any usual use case of that widget.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

                  Yes, exactly.

                  Do you have any suggestion to do such a functionalty?

                  I see it on IOS apps, if Kinetic Scrolling not used.

                  On Android apps it is different. If you press on an item, app highlight that item, However if you move the cursor (or your finger on touch screens) without relesing, that item can not be selected again.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    You would probably need to customize the mouse event handling by subclassing QListWidget

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      anticore
                      wrote on last edited by
                      #10

                      Yes.

                      Should I do this with code handling or a QListWidget method?

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Have a look at the mouseXXXEvent methods

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          anticore
                          wrote on last edited by
                          #12

                          Ok,

                          Thank you for your help...

                          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