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. [solved] QListView delegated items are displayed only by in runtime created QListView

[solved] QListView delegated items are displayed only by in runtime created QListView

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.5k 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.
  • SavedS Offline
    SavedS Offline
    Saved
    wrote on last edited by
    #1

    Hello all,

    I think my problem is easy to solve and needs only short explanation.

    My problem description: If I add a QListView to my MainWindow in Qt-Creator designer and overwrite it's pointer in my code with derived QListView, my custom items are not displayed in the QListView. But if I create my derived QListView and add it to the ui in MainWindow constructor, the items are displayed well.

    My code:

    @QListView *listView = new DerivedListView(); // ignores MouseMove events
    ui->listView = listView; // this QListView was added in Designer and doesn't display the items
    ui->verticalLayout->addWidget(listView); // this QListView displays the items well.@

    Later the QListView gets a derived AbstractItemDelegate and AbstractListModel.

    What could be the reason for this behavior?

    Thank you.

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

      Hi and welcome to devnet,

      @ui->listView = listView@

      You only replace the pointer value so you still see the original listView since it's already been layouted in your MainWindow, call show on it and see what happens.

      @ui->verticalLayout->addWidget(listView);@

      Now, you are adding your new widget to the layout of your Designer based MainWindow, thus making your custom list view managed by it

      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
      • SavedS Offline
        SavedS Offline
        Saved
        wrote on last edited by
        #3

        If I call the show methode the ListView will be displayed outside the MainWindow.

        Ok, thank you.

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

          If your derived QListView only ignores mouse event, you could avoid it and set an eventFilter on it, it might simplify your code (or depending on why you want mouse event to be ignored, you can also just disable the selection mode)

          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
          • SavedS Offline
            SavedS Offline
            Saved
            wrote on last edited by
            #5

            I have to ignore the DragSelection in MultiSelectionMode. But because of MVC architecture I want to separate the QListView actions from MainWindow - and want avoid the event filtering on MainWindow.

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

              You can also create a dedicated object that does the filtering

              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

              • Login

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