Results 1 to 6 of 6

Thread: ReImplement showPopup for my QComboBOx

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Posts
    12
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default ReImplement showPopup for my QComboBOx

    Hi,

    I think that the problem is easy, but i don't know how to process for this:
    I just want to reimplement QComboBox::showPopup() in my new class that inherit from QComboBox, but I want to reuse the given code and just add one line.
    I can't because:

    `QComboBoxPrivate* QComboBox::d_func()' is private
    mycombobox.cpp:24: error: within this context
    mycombobox.cpp:31: error: invalid use of undefined type `struct QAbstractItemView'
    d:/Outils/Qt/qt/qt/include/QtGui/../../src/gui/itemviews/qabstractitemdelegate.h:59: error: forward declaration of `struct QAbstractItemView'
    mycombobox.cpp:31: error: invalid use of undefined type `struct QComboBoxPrivate'
    d:/Outils/Qt/qt/qt/include/QtGui/../../src/gui/widgets/qcombobox.h:60: error: forward declaration of `struct QComboBoxPrivate'
    mycombobox.cpp:32: error: `QItemSelectionModel' has not been declared
    mycombobox.cpp:32: error: `ClearAndSelect' was not declared in this scope
    mycombobox.cpp:33: error: invalid use of undefined type `struct QComboBoxPrivate'
    ...
    My code:

    Qt Code:
    1. #include <QComboBox>
    2. class MyComboBox : public QComboBox
    3. {
    4. public:
    5. MyComboBox (QWidget *parent);
    6. virtual void showPopup();
    7. };
    8.  
    9. /*!
    10.   Displays the list of items in the combobox. If the list is empty
    11.   then the no items will be shown.
    12.   If you reimplement this function to show a custom pop-up, make
    13.   sure you call hidePopup() to reset the internal state.
    14. */
    15. void MyComboBox::showPopup()
    16. {
    17. // i just try this part of the code
    18. Q_D(QComboBox);
    19. if (count() <= 0)
    20. return;
    21.  
    22. QStyle * const style = this->style();
    23.  
    24. view()->selectionModel()->setCurrentIndex(d->currentIndex,
    25. QItemSelectionModel::ClearAndSelect);
    26.  
    27. QComboBoxPrivateContainer* container = d->viewContainer();
    28.  
    29. /* ... */
    To copy to clipboard, switch view to plain text mode 

    How could i reuse the code for this method please ?

    Thanks.

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ReImplement showPopup for my QComboBOx

    you can not use it.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: ReImplement showPopup for my QComboBOx

    In general you can't. You should use QComboBox::view() and QComboBox::setView() instead.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:

    sedi (8th April 2012)

  5. #4
    Join Date
    Jul 2009
    Posts
    12
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: ReImplement showPopup for my QComboBOx

    Quote Originally Posted by wysota View Post
    In general you can't. You should use QComboBox::view() and QComboBox::setView() instead.
    Thanks !!!

    I just use view() :

    Qt Code:
    1. void MyComboBox::showPopup()
    2. {
    3. view()->move(view()->x(), view()->y() - view()->height()/2);
    4. QComboBox::showPopup();
    5. }
    To copy to clipboard, switch view to plain text mode 

    I reimplement the method becasue I would like to show the items 1, 2 and 3 in a view above the QComboBox button, and the items 4, 5 and 6 below the button in a other view.
    How could i do that ? : create two QListWidget and separate the QComboBox view in the two QListWidget ?

    Thanks again

  6. The following user says thank you to ber0y for this useful post:

    sedi (8th April 2012)

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: ReImplement showPopup for my QComboBOx

    I think all you need to do is to move the popup up (change its geometry) using something like:

    Qt Code:
    1. view()->window()->move(...);
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    sedi (8th April 2012)

  9. #6
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: ReImplement showPopup for my QComboBOx

    It's an old thread, but the problem is still there. I needed some time to see the obvious: you have to call the base class "showPopup" before moving the popup item. This works well:

    Qt Code:
    1. void MyQComboBox::showPopup() {
    2. QComboBox::showPopup();
    3. QWidget *popup = this->findChild<QFrame*>();
    4. popup->move(popup->x(),popup->y()-this->height()-popup->height());
    5. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QCombobox showPopup problem
    By SailinShoes in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2008, 11:16
  2. QCombobox showPopup
    By SailinShoes in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2008, 12:21
  3. QComboBox - Few virtual methods
    By gruszczy in forum Qt Programming
    Replies: 17
    Last Post: 16th July 2008, 16:08
  4. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 19:25
  5. using QComboBox as an ItemView
    By EricTheFruitbat in forum Qt Programming
    Replies: 3
    Last Post: 24th January 2007, 16:14

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
  •  
Qt is a trademark of The Qt Company.