Results 1 to 10 of 10

Thread: QcomboBox item height

  1. #1
    Join Date
    Apr 2009
    Posts
    18
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default QcomboBox item height

    Hi all,

    I would like to set with stylesheet the item's height when combo's pop up opens.

    any suggestion?

    thank you

    Beppe

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QcomboBox item height

    It seems not possible with style sheet...
    I tried -
    Qt Code:
    1. {
    2. font: 75 48pt "Times New Roman";
    3. }
    To copy to clipboard, switch view to plain text mode 

    but it doesnt work

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QcomboBox item height

    try to set an item size throught a model
    Qt Code:
    1. #include <QtGui>
    2. #include <QApplication>
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication app(argc, argv);
    7. cb.addItems(QStringList() << "a" << "b" << "c" << "d");
    8. cb.model()->setData(cb.model()->index(0, 0), QSize(100, 100), Qt::SizeHintRole);
    9. cb.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  4. The following 2 users say thank you to spirit for this useful post:

    Beppe (15th June 2009), chinalski (16th November 2013)

  5. #4
    Join Date
    Apr 2009
    Posts
    18
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QcomboBox item height

    Thank you spirit, it works.

    I have another problem. I would like to change the scrollbar of the items' list. I have to use the function

    Qt Code:
    1. void QComboBox::setView ( QAbstractItemView * itemView )
    To copy to clipboard, switch view to plain text mode 

    and set my scrollbar for QAbstractItemView using

    Qt Code:
    1. setVerticalScrollBar ( QScrollBar * )
    To copy to clipboard, switch view to plain text mode 

    ???

    Am i rught ?

  6. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QcomboBox item height

    you can get a view using QComboBox::view and then set a new scroll bar.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. The following user says thank you to spirit for this useful post:

    Beppe (16th June 2009)

  8. #6
    Join Date
    Apr 2009
    Posts
    18
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QcomboBox item height

    Thanks again spirit, it works, but my scrollbar is not correctly displayed in the combobox's pop up (see scrollbarComboBox.JPG). When I add my scrollbar to a scrollarea it is correctly displayed (see scrollbarScrollArea.JPG).

    my combo box code is

    mycombobox.cpp

    Qt Code:
    1. #include "mycombobox.h"
    2.  
    3.  
    4. myComboBox::myComboBox(QWidget * parent)
    5. : QComboBox(parent)
    6. {
    7. comboScrollBar = new myscrollbar(0);
    8.  
    9.  
    10. this->view()->setVerticalScrollBar(comboScrollBar);
    11.  
    12.  
    13. this->setStyleSheet(" \
    14. QComboBox { border: 1px solid gray;\
    15. border-radius: 3px;\
    16. padding: 1px 18px 1px 3px; \
    17. min-width: 6em; \
    18. } \
    19. \
    20. QComboBox:editable {\
    21. background: white;\
    22. }\
    23. \
    24. QComboBox:!editable, QComboBox::drop-down:editable {\
    25. background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\
    26. stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,\
    27. stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);\
    28. }\
    29. \
    30. \
    31. QComboBox:!editable:on, QComboBox::drop-down:editable:on {\
    32. background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\
    33. stop: 0 #D3D3D3, stop: 0.4 #D8D8D8,\
    34. stop: 0.5 #DDDDDD, stop: 1.0 #E1E1E1);\
    35. }\
    36. QComboBox:on {\
    37. padding-top: 3px;\
    38. padding-left: 4px;\
    39. }\
    40. QComboBox::drop-down {\
    41. subcontrol-origin: padding;\
    42. subcontrol-position: top right;\
    43. width: 54px;\
    44. border-left-width: 1px;\
    45. border-left-color: darkgray;\
    46. border-left-style: solid; \
    47. border-top-right-radius: 3px; \
    48. border-bottom-right-radius: 3px;\
    49. }\
    50. QComboBox::down-arrow {\
    51. image: url(b_droplist.png);\
    52. }\
    53. \
    54. QComboBox::down-arrow:on { \
    55. top: 1px;\
    56. left: 1px;\
    57. }\
    58. QComboBox QAbstractItemView {\
    59. border: 2px solid darkgray;\
    60. selection-background-color: lightgray;\
    61. }\
    62. ");
    63. }
    To copy to clipboard, switch view to plain text mode 

    mycombobox.h

    Qt Code:
    1. #ifndef MYCOMBOBOX_H
    2. #define MYCOMBOBOX_H
    3.  
    4. #include <QtCore>
    5. #include <QtGui>
    6. #include <QComboBox>
    7.  
    8. #include "myscrollbar.h"
    9.  
    10.  
    11. class myComboBox : public QComboBox
    12. {
    13. Q_OBJECT
    14. Q_DISABLE_COPY(myComboBox)
    15. public:
    16. myComboBox(QWidget * parent = 0);
    17.  
    18. private:
    19. myscrollbar *comboScrollBar;
    20. };
    21.  
    22.  
    23. #endif // MYCOMBOBOX_H
    To copy to clipboard, switch view to plain text mode 


    and my scrollbar code is

    myscrollbar.cpp


    Qt Code:
    1. myscrollbar::myscrollbar(QWidget * parent)
    2. : QScrollBar(Qt::Vertical, parent)
    3. {
    4.  
    5.  
    6. this->setStyleSheet(" \
    7. QScrollBar::vertical {\
    8. background:lightgray;\
    9. border-color:black;\
    10. border-style:solid;\
    11. width: 15px;\
    12. margin-top:1px;\
    13. margin-bottom:1px;\
    14. }\
    15. \
    16. QScrollBar::add-page:vertical, \
    17. QScrollBar::sub-page:vertical {\
    18. background: none;\
    19. }\
    20. \
    21. QScrollBar::add-line:vertical{\
    22. background:none;\
    23. } \
    24. \
    25. QScrollBar::sub-line:vertical { \
    26. background:none;\
    27. } \
    28. \
    29. QScrollBar::handle:vertical {\
    30. background: url(slider.png);\
    31. \
    32. border-color:black;\
    33. border-style:solid;\
    34. border-width:1px;\
    35. } \
    36. \
    37. QScrollBar::add-line:pressed,\
    38. QScrollBar::sub-line:pressed,\
    39. QScrollBar::handle:pressed{\
    40. background:lightgray;\
    41. background: url(slider.png);\
    42. }\
    43. ");
    44. }
    45.  
    46. QSize myscrollbar::sizeHint() const
    47. {
    48. return QSize(50,96);
    49. }
    50.  
    51. QSize myscrollbar::minimumSizeHint() const
    52. {
    53. return QSize(50,96);
    54. }
    To copy to clipboard, switch view to plain text mode 

    myscrollbar.h


    Qt Code:
    1. #ifndef MYSCROLLBAR_H
    2. #define MYSCROLLBAR_H
    3.  
    4. #include <QtCore>
    5. #include <QtGui>
    6. #include <QScrollBar>
    7.  
    8. class myscrollbar : public QScrollBar
    9. {
    10. Q_OBJECT
    11. Q_DISABLE_COPY(myscrollbar)
    12. public:
    13. myscrollbar(QWidget * parent = 0);
    14.  
    15. QSize sizeHint() const;
    16. QSize minimumSizeHint() const;
    17. };
    18.  
    19. #endif // MYSCROLLBAR_H
    To copy to clipboard, switch view to plain text mode 



    have you any idea of the problem ?
    Attached Images Attached Images

  9. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QcomboBox item height

    why do you create own scroll bar? you just can set a style sheet for already created scrollbar in a combobox, e.g.
    Qt Code:
    1. ...
    2. cb->view()->setStyleSheet(...);
    3. ...
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. ...
    2. cb->view()->verticalScrollBar()->setStyleSheet(...);
    3. ...
    To copy to clipboard, switch view to plain text mode 
    or I missed something?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  10. #8
    Join Date
    Apr 2009
    Posts
    18
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QcomboBox item height

    I'm not expert, so you may be right.

    Actually I want to use my scrollbar for other widget such as ScrollArea and I think my code is more flexible if I define my custom scrollbar.

  11. #9
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QcomboBox item height

    if you wanna apply your style sheet for all scrollbars in your app then use QApplication::setStyleSheet.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  12. #10
    Join Date
    Apr 2009
    Posts
    18
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QcomboBox item height

    Thank you for the suggestion

Similar Threads

  1. Same height for QComboBox and QPushButton
    By cevou in forum Qt Programming
    Replies: 5
    Last Post: 12th May 2012, 08:56
  2. Determining the height of an item in a QListWidget
    By negritot in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2009, 20:18
  3. [solved]QListView dynamic item height
    By kernel_panic in forum Qt Programming
    Replies: 8
    Last Post: 17th March 2009, 15:05
  4. Cannot select an item in QComboBox
    By Declan in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2007, 09:08
  5. QComboBox and item
    By drow in forum Qt Programming
    Replies: 4
    Last Post: 14th June 2006, 10:04

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.