How to change Qcombobox popup width



  • Hi, every body

    I have subclasse QtableWidget to to accept Qcombobox in their cell,

    I have maked that combobox show a Qtableview when the list popup,

    but i have a probleme the Qtableview not showed completely, how i can acheive this ??


  • Moderators

    you can subclass QComboBox and reimplement showPopup() method if you need the size content dependent. Something like this:
    @
    void MyComboBox::showPopup()
    {
    this->view()->setMinimumWidth(this->view()->sizeHintForColumn(0));
    QComboBox::showPopup();
    }
    @



  • i have implemented this but still not working as i want
    ( Qcombobox editor should not resize , only the view inside it that can be resized )

    her is my code

    @void MyQComboBox::showPopup()
    {
    QWidget *view = this->view() ;
    int width = view->width();
    this->setMinimumWidth(width);
    QComboBox::showPopup();
    }@

    it's like so

    ////////////////////////////////
    // combobox //
    //////////////////////////////////////////////////////////////////////////////////
    // Qtableview her with all cells inside it ** Horizontal Header //
    /////////////////////////////////////////////////////////////////////////////////
    /// row 0 //
    /////////////////////////////////////////////////////////////////////////////////
    /// row 1 //
    /////////////////////////////////////////////////////////////////////////////////
    /// row 2 //
    /////////////////////////////////////////////////////////////////////////////////


  • Moderators

    and you can't see a difference between my and your code?!
    You set the minimum width to width... you wont notice anything with that code.



  • i can't use this code @this->view()->setMinimumWidth(this->view()->sizeHintForColumn(0));@

    the compiler show me an error !!!

    this->view() it's ok but this->view()->setMinimumWidth() it's not possible
    (because there is no member setMinimumWidth of this->view())



  • [quote author="raven-worx" date="1375894826"]and you can't see a difference between my and your code?!
    You set the minimum width to width... you wont notice anything with that code.[/quote]

    Ok, i have figured out what you mean

    @void MyQComboBox::showPopup()
    {
    QWidget *view = this->view() ;
    // i can't use this because
    // QWidget hasn't a method (sizeHintForColumn())
    // so i have used this
    this->setMinimumSize(view->sizeHint());
    // but still i have a problem
    QComboBox::showPopup();
    }
    @

    like so,

    ////////////////////////////////////
    // combobox //
    // //
    // I don't need this Height //
    // //
    // //
    ////////////////////////////////////
    // Qtableview her with all //
    //cells inside it ** Horizon //
    // Header // //
    ///////////////////////////////////
    /// row 0 // //
    //////////////////////////////////
    /// row 1 //
    /////////////////////////////////


  • Moderators

    this->view() returns an QAbstractItemView which is derived from QWidget. QWidget has a method named setMinimumWidth() ....
    what Qt version do you use?!



  • [quote author="raven-worx" date="1375899990"]this->view() returns an QAbstractItemView which is derived from QWidget. QWidget has a method named setMinimumWidth() ....
    what Qt version do you use?![/quote]

    Sure, QWidget has a member function setMinimumWidth(),

    my problem is inside setMinimumWidth(),

    this->view()->sizeHintForColumn(0) ( QWidget hasn't a methode sizeHintForColumn(0)


  • Moderators

    no...but QAbstractItemView does!
    Since you implicitly cast the view instance to a QWidget it's clear that the compiler complains about it!



  • [quote author="raven-worx" date="1375905485"]no...but QAbstractItemView does!
    Since you implicitly cast the view instance to a QWidget it's clear that the compiler complains about it![/quote]

    I have no idea how i can do this


  • Moderators

    change the line
    @
    QWidget *view = this->view() ;
    @
    to
    @
    QAbstractItemView *view = this->view() ;
    @

    or just use the code i've posted in first place!



  • [quote author="raven-worx" date="1375946208"]change the line
    @
    QWidget *view = this->view() ;
    @
    to
    @
    QAbstractItemView *view = this->view() ;
    @

    or just use the code i've posted in first place![/quote]

    also not working for me , always the width of Qtableview don't increased



  • how i can increase only the width of popup (Qtableview) ???



  • like so,
    ////////////////////////////////
    // combobox //
    //////////////////////////////////////////////////////////////////////////////////
    // Qtableview her with all cells inside it ** Horizontal Header //
    /////////////////////////////////////////////////////////////////////////////////
    /// row 0 //
    /////////////////////////////////////////////////////////////////////////////////
    /// row 1 //
    /////////////////////////////////////////////////////////////////////////////////
    /// row 2 //
    /////////////////////////////////////////////////////////////////////////////////



  • no body know about this ?



  • plz inform me if my question is clear or no ?



  • i have used this but not working



  • This works perfect, Thank you very much.

    [quote author="raven-worx" date="1375879559"]you can subclass QComboBox and reimplement showPopup() method if you need the size content dependent. Something like this:
    @
    void MyComboBox::showPopup()
    {
    this->view()->setMinimumWidth(this->view()->sizeHintForColumn(0));
    QComboBox::showPopup();
    }
    @[/quote]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.