Results 1 to 3 of 3

Thread: Qt5 handling multiple widgets proficiently

  1. #1
    Join Date
    Jun 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Qt5 handling multiple widgets proficiently

    Hi all,

    I enclosed a screenshot of my current project.

    bm.png

    I have a QTreeView on the left panel and a custom QWidget on the right panel. What I would like to have is switching QWidget when the user clicks on an element of the QTreeView. Each "radio" element (as it is mentionned on the screenshot) would have its own QWidget where I intend to have lots of information on the radio element.

    What I first tried to do, is to attach a Widget (or its pointer) to a QStandardItem or the model index of the QTreeView/QStandardItemModel. I tried to do it with QVariant and the setData() method but it doesn't work. I get error messages from the compiler or if I manage to avoid the error messages I get NULL pointers to my widget.

    I'm not sure now if it's a good idea to attach a QWidget pointer to a Qt element.

    So what I'm asking is : is there a good way to handle multiple widget instances on a layout ? Can someone hint me an idea on how to achieve what I want to do ?

    I hope I'm clear enough. Don't hesitate to ask for more info if it wasn't clear.

    Thanks for your help

    Is there a best way to switch

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt5 handling multiple widgets proficiently

    A simple solution is to populate a QStackedWidget with one widget for each "radio" item, and call QStackedWidget::setCurrentIndex() with the index of the element.

  3. #3
    Join Date
    Jun 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt5 handling multiple widgets proficiently

    Thanks for your answer, I didn't know this widget.

    One cool thing is I can store the index of the QStackedWidget in the QStandardItemModel element as it is an integer.

    So I'll be able to switch easily between widgets.

Similar Threads

  1. Problem with event handling of multiple windows
    By rakefet in forum Qt Programming
    Replies: 2
    Last Post: 11th April 2014, 21:40
  2. Multiple Forms Handling
    By eva2002 in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2010, 06:24
  3. QLocalServer with multiple clients — proper handling
    By indiocolifa in forum Qt Programming
    Replies: 4
    Last Post: 28th July 2010, 00:01
  4. Handling multiple forms
    By msmihai in forum Qt Programming
    Replies: 4
    Last Post: 6th December 2008, 13:41
  5. Handling multiple UDP sockets
    By ecphora in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 20:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.