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] Additional widget like in QComboBox
QtWS25 Last Chance

[SOLVED] Additional widget like in QComboBox

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 5.7k 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.
  • R Offline
    R Offline
    RazrFalcon
    wrote on last edited by
    #1

    How to create a widget for QPushButton, that show widget like QComboBox?
    I want to create a widget like QComboBox, but in this additional widget I need to see QTableWidget, not a QListWidget (or what is there).
    Thanks.

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      Maybe "this FAQ":http://developer.qt.nokia.com/faq/answer/how_can_i_make_a_qcombobox_have_multiple_selection can inspire you.

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RazrFalcon
        wrote on last edited by
        #3

        I tried it. But code like this has no effect...
        @void showPopup()
        {
        QComboBox::showPopup();
        QStandardItemModel *model = new QStandardItemModel(3,3);
        view()->setModel(model);
        }@
        Where is my problem?

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

          Your view is still a QListView, not a QTableView. Lucky for you, QComboBox also has a setView method...

          1 Reply Last reply
          0
          • R Offline
            R Offline
            RazrFalcon
            wrote on last edited by
            #5

            Amazing! Thanks a lot. Now it work as I want.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              RazrFalcon
              wrote on last edited by
              #6

              I have new problem.
              I didn't understand how to reimplement addItem() function to add items to model/table.
              If I added new item to QStandardItemModel, which I set to view() in constructor, then my combobox are disabled. I can't open it.

              Example:
              @MyComboBox::MyComboBox(QWidget *parent) : QComboBox(parent)
              {
              setView(new QTableView);
              model = new QStandardItemModel(3,3);
              view()->setModel(model);
              addItem(0,0,"A");
              addItem(1,0,"B");
              addItem(2,0,"C");
              }

              void MyComboBox::addItem(int row, int col, const QString &text)
              {
              QStandardItem *item = new QStandardItem(text);
              model->setItem(row,col,item); // model - is a global QStandardItemModel
              }@

              Where is my problem? Should I add items directly to default QAbstractItemModel?
              Thanks.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                First of all: don't use globals unless you really, really have to (basically: never). What happens in your case if you want more than one of these special combo boxes in your application? Just make the model a member of the class.

                I am not sure how nice QCombobox plays if you use your own model and not the one that QComboBox is aware of, but my guess would be: not nice. If the QComboBox's model is empty, then it makes sense QComboBox hides the drop down, right? So, why don't you tell QComboBox about your own model by calling QComboBox::setModel()?

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  RazrFalcon
                  wrote on last edited by
                  #8

                  Thanks.
                  QComboBox::setModel() helps.

                  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