Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: QListWidget - inconsistency across operating systems?

  1. #1
    Join Date
    Feb 2007
    Posts
    29
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default QListWidget - inconsistency across operating systems?

    In native windows API when you select an item from a listbox window the width of the selection highlighting is as wide as the listbox.

    In a QListWidget, when you select an item the selection highlighting is only as wide as the text.

    Is there anyway I can change the style of a QListWidget to make it look more like a windows listbox?

    Here's exactly what I'm talking about

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QListWidget styles?

    Quote Originally Posted by scwizard View Post
    In native windows API when you select an item from a listbox window the width of the selection highlighting is as wide as the listbox.

    In a QListWidget, when you select an item the selection highlighting is only as wide as the text.

    Is there anyway I can change the style of a QListWidget to make it look more like a windows listbox?

    Here's exactly what I'm talking about
    I think QListView isn't designed too look like that. There is a hackish way to achieve it with a QListView (1), but I'd try with QTreeView (2) instead.

    Hackish solution 1:
    Override QListWidget::resizeEvent() and make the width of QListView::gridSize() to follow the width of the widget/viewport.

    Better solution 2:
    A single column QTreeView (or QTreeWidget if you prefer the convenience views) stretches the column to be like that. Hide the header, disable root decoration and add only top level items and voila!
    J-P Nurmi

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

    Default Re: QListWidget styles?

    There is an elegant solution. Just make sure that movement property is set to Static and isWrapping property is set to false. If you insert a QListWidget into Designer, its default properties are set correctly and the whole width of the list is highlighted when selecting.

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

    scwizard (19th February 2007)

  5. #4
    Join Date
    Feb 2007
    Posts
    29
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget styles?

    Quote Originally Posted by wysota View Post
    There is an elegant solution. Just make sure that movement property is set to Static and isWrapping property is set to false. If you insert a QListWidget into Designer, its default properties are set correctly and the whole width of the list is highlighted when selecting.
    Thanks, but being a Qt newbie I have no idea how to manipulate properties. I read about Qt's Property System, but I don't really understand it.

    I did wrote Sidebox->setWrapping(true); but it didn't do anything.
    I'm not sure how to setMovement to static.

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

    Default Re: QListWidget styles?

    Qt Code:
    1. Sidebox->setWrapping(false); // I said false, not true
    2. Sidebox->setMovement(QListView::Static);
    To copy to clipboard, switch view to plain text mode 

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

    scwizard (19th February 2007)

  8. #6
    Join Date
    Feb 2007
    Posts
    29
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget styles?

    Odd, it still doesn't work. Nothing appears to have changed. Just try compiling the following code:

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char** argv) {
    4. QApplication app(argc, argv);
    5.  
    6. QListWidget* Sidebox = new QListWidget;
    7.  
    8. Sidebox->setWrapping(false);
    9. Sidebox->setMovement(QListView::Static);
    10.  
    11. new QListWidgetItem(QObject::tr("Test"), Sidebox);
    12. new QListWidgetItem(QObject::tr("Hello world"), Sidebox);
    13.  
    14. Sidebox->show();
    15. return app.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 

    Whether or not lines 8 and 9 are included makes no difference, the way the listwidget looks is the same.
    Last edited by scwizard; 19th February 2007 at 16:02.

  9. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QListWidget styles?

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char** argv) {
    4. QApplication app(argc, argv);
    5.  
    6. QListWidget* Sidebox = new QListWidget;
    7.  
    8. Sidebox->setWrapping(false); // <-- _false_
    9. Sidebox->setMovement(QListView::Static);
    10.  
    11. new QListWidgetItem(QObject::tr("Test"), Sidebox);
    12. new QListWidgetItem(QObject::tr("Hello world"), Sidebox);
    13.  
    14. Sidebox->show();
    15. return app.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 

    Edit: Btw, thanks Wysota for pointing it out!
    Last edited by jpn; 19th February 2007 at 15:59.
    J-P Nurmi

  10. #8
    Join Date
    Feb 2007
    Posts
    29
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget styles?

    No no no. I tried true and false because neither of them worked. The copy and paste just happened to be from when it was true.

    I edited my above post so it would was false. My above post is still correct.

  11. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QListWidget styles?

    Which exact version of Qt are you using? Works fine with 4.2.2:
    Attached Images Attached Images
    J-P Nurmi

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

    Default Re: QListWidget styles?

    Quote Originally Posted by wysota View Post
    Qt Code:
    1. Sidebox->setWrapping(false); // I said false, not true
    To copy to clipboard, switch view to plain text mode 
    Quote Originally Posted by jpn View Post
    Qt Code:
    1. Sidebox->setWrapping(false); // <-- _false_
    To copy to clipboard, switch view to plain text mode 
    Quote Originally Posted by scwizard View Post
    Qt Code:
    1. Sidebox->setWrapping(true);
    To copy to clipboard, switch view to plain text mode 
    This one is really nice

    Edit: Btw, thanks Wysota for pointing it out!
    Sure, no problem. The question was asked (and answered) before and I personally faced the same problem some time ago... And once you think of it, it's an obvious and logical behaviour for wrapping movable items.

    Quote Originally Posted by scwizard View Post
    Qt Code:
    1. Sidebox->setWrapping(false);
    To copy to clipboard, switch view to plain text mode 
    That's why we limit the time to edit own posts... It used to say "true" here a minute ago

  13. #11
    Join Date
    Feb 2007
    Posts
    29
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget styles?

    Ok, so the fault isn't in the code. Apparently...

    Strange indeed...

    This is the code I'm using:
    #include <QtGui>

    int main(int argc, char** argv) {
    QApplication app(argc, argv);
    QListWidget* Sidebox = new QListWidget;

    Sidebox->setWrapping(false); // <-- _false_
    Sidebox->setMovement(QListView::Static);

    new QListWidgetItem(QObject::tr("Test"), Sidebox);
    new QListWidgetItem(QObject::tr("Hello world"), Sidebox);

    Sidebox->show();
    return app.exec();
    }

    jpn says it works with his build of Qt. jpn is using Qt (open source) 4.2 on Linux (as I can see from his screenshot).
    I'm using Qt (open source) 4.2 on Windows (like it says to the right of my username). It doesn't work with my build.
    Last edited by scwizard; 19th February 2007 at 16:36.

  14. #12
    Join Date
    Feb 2007
    Posts
    29
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Inconsistancy across operating systems?

    I have a favor to ask of the kind people at this forum. Could you copy, paste and compile the following code and give a screenshot of the result (with a list item selected).

    I'm asking because jpn got this when he compiled the below program. My screenshot and his screenshot have noticeable differences. The selection for his screenshot stretches the length of the widget, but only stretchs the length of the text for mine. My best guess is that the reason for this is that one program was compiled on linux and the other on windows.

    The code:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char** argv) {
    4. QApplication app(argc, argv);
    5. QListWidget* Sidebox = new QListWidget;
    6.  
    7. Sidebox->setWrapping(false); // <-- _false_
    8. Sidebox->setMovement(QListView::Static);
    9.  
    10. new QListWidgetItem(QObject::tr("Test"), Sidebox);
    11. new QListWidgetItem(QObject::tr("Hello world"), Sidebox);
    12.  
    13. Sidebox->show();
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    The screenshot:
    Attached Images Attached Images
    Last edited by wysota; 19th February 2007 at 21:41. Reason: missing [code] tags

  15. #13
    Join Date
    Feb 2007
    Posts
    29
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Inconsistancy across operating systems?

    Note:
    I tested this on two different computer both running windows (XP Home edition) and the latest (4.2.2 open source edition) version of Qt.

    Here's the screencapture from my other computer.

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

    Default Re: Inconsistancy across operating systems?

    You can omit the wrapping and movement properties as they are by default set to false and static.

  17. #15
    Join Date
    Feb 2007
    Posts
    29
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget styles?

    @Whichever mod moved and merged:
    I'm fine with you merging the topics, but it'd be nice if you'd changed the title of the real topic (as opposed to the move ghost) as "Inconsistency across operating systems?" as that better reflects the actual topic at the moment. I'm apparently not able to do it my self (or edit the first post here at all for that matter).

  18. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Inconsistancy across operating systems?

    Try running your application with Plastique style: "app -style plastique"

  19. The following user says thank you to jacek for this useful post:

    scwizard (19th February 2007)

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

    Default Re: Inconsistancy across operating systems?

    Cleanlooks works as well.

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

    scwizard (19th February 2007)

  22. #18
    Join Date
    Feb 2007
    Posts
    29
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget - inconsistency across operating systems?

    Those looks quite nice. I think I may end up just changing the style of the application if there is no way to get listwidget item selections to span the length of the widget in a windows style.

  23. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget - inconsistency across operating systems?

    Quote Originally Posted by scwizard View Post
    if there is no way to get listwidget item selections to span the length of the widget in a windows style.
    At least there is no inconsistency across operating systems --- just the windows style behave a bit differently (on Linux too).

    Have you tried the windowsxp style?

  24. The following user says thank you to jacek for this useful post:

    scwizard (20th February 2007)

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

    Default Re: QListWidget - inconsistency across operating systems?

    Quote Originally Posted by jacek View Post
    just the windows style behave a bit differently (on Linux too).
    All motif-like styles (motif, cde, windows) behave that way. You can always make a proxy style to correct(*) that behaviour in a style independent way.

    ---
    (*) - change

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

    scwizard (20th February 2007)

Similar Threads

  1. Replies: 13
    Last Post: 15th December 2006, 11:52

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.