Results 1 to 6 of 6

Thread: change text color for handmade Widget in QListWidget

  1. #1
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Post change text color for handmade Widget in QListWidget

    Hello all. I need your advice. I have a QListWidget, and QListWidgetItem
    QListWidgetItem *item = new QListWidgetItem;
    item->setSizeHint(size);
    ui.listWidget->addItem(item);

    and I add my handmade navigation widget to item
    ui.listWidget->setItemWidget(itm, navWidget);

    Now I change background for selected item
    QListWidget:item:selected:active
    {
    background: gray;
    color: yellow;
    }
    and I want my navigation widget changed text color when item, to which it belongs, is selected. If another item selected, previous item navigation widget return his previous color text. How I can release this task?
    Attached Images Attached Images
    Last edited by Holiday; 31st October 2014 at 19:08. Reason: the task is complete

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: change text color for handmade Widget in QListWidget

    Give your nav widget a function to set it active (or not) and change its properties/paint it accordingly. Then capture when the current item of the list widget changes and set the previous widget (if there is one) inactive and the new widget (if there is one) active.

    QListWidget::currentItemChanged()

  3. The following user says thank you to ChrisW67 for this useful post:

    Holiday (1st November 2014)

  4. #3
    Join Date
    Oct 2014
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: change text color for handmade Widget in QListWidget

    The task is solved!

  5. #4
    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: change text color for handmade Widget in QListWidget

    Had you also tried by setting stylesheet for -
    QListWidget:item:selected:!active ?

  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: change text color for handmade Widget in QListWidget

    Indeed. That might be easier (if a tiny bit slower). You can tell I don't do stylesheets.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: change text color for handmade Widget in QListWidget

    I don't think stylesheets are going to work if a widget is put in a cell. The stylesheet is applied to the item and not to the widget that replaces it. I'd be very surprised if it worked.
    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.


Similar Threads

  1. Replies: 0
    Last Post: 25th April 2014, 08:59
  2. change text color on QRadioButton
    By vonCZ in forum Newbie
    Replies: 4
    Last Post: 7th November 2012, 20:05
  3. Replies: 3
    Last Post: 16th July 2012, 15:04
  4. Replies: 3
    Last Post: 22nd January 2010, 16:46
  5. how to change text color in QTableView?
    By phillip_Qt in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2008, 10:03

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.