Results 1 to 12 of 12

Thread: checkbox implementation in QTableWidget display issue

  1. #1
    Join Date
    Feb 2010
    Location
    INDIA
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question checkbox implementation in QTableWidget display issue

    Hello

    I have an issue with checkbox implementation in QTableWidget when running on platform other than windows. When running on other platform, the checkbox visibilty is less. The tick color of Qt::checked seems white and its difficult to get to know whether it is ticked or not.

    The implementation of Check box is shown below.
    Qt Code:
    1. QTableWidget* m_GridWgt = new QTableWidget(3,3);
    2. qItem->setFlags(Qt::ItemIsEnabled|Qt::ItemIsUserCheckable);
    3. qItem->setCheckState(Qt::Checked);
    4. m_GridWgt->setItem(i, col, qItem);
    To copy to clipboard, switch view to plain text mode 

    Is it possible to modify check box color (cell color and tick color of check box) in QTablewidget?

    Also to customise the checkbox in a column, I have use another way using delegate item. But I couldnt find a way to set QModelIndex with data Qt::CheckRole.

    Is it possible to use QModelIndex with QTableWidget or it works fine only for QTableView?

    thx
    P

  2. #2
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: checkbox implementation in QTableWidget display issue

    u can use stylesheet for coloring the table

    Qt Code:
    1. QTableWidget QTableCornerButton::section {
    2. background: red;
    3. border: 2px outset red;
    4. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. m_GridWgt->setStyleSheet("selection-background-color: qlineargradient(x1: 0, y1: 0, x2: 0.5, y2: 0.5,stop: 0 #FF92BB, stop: 1 white)");
    To copy to clipboard, switch view to plain text mode 

    this will change the background color when u select a row

    i dont know how to change the checkbox;s color and tick color

    Bala

  3. #3
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: checkbox implementation in QTableWidget display issue

    hi prajesh

    This will change the background color of the checkbox.
    Qt Code:
    1. m_GridWgt->setStyleSheet("QTableWidget::indicator:checked {background-color:blue;}");
    To copy to clipboard, switch view to plain text mode 

    i think. ,the following stylesheet will be handy for ur need
    pls prepare the image for checking;
    Qt Code:
    1. m_GridWgt->setStyleSheet("QTreeView::indicator:checked {image: url(path);}");
    To copy to clipboard, switch view to plain text mode 

    hope it helps

    Bala

  4. #4
    Join Date
    Feb 2010
    Location
    INDIA
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: checkbox implementation in QTableWidget display issue

    Hello Bala,

    Yes that works for me and thanks for your reply. But to calrify a doubt, by this method we can set background color for checked or unchecked state ,but I couldnt see tick on the check box if I set style sheet . Is that possible to set color to tick?

    rgds
    Prajesh

  5. #5
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: checkbox implementation in QTableWidget display issue

    hi prajesh,
    Have a image for tick mark with the prefered color
    and use the stylesheet
    m_GridWgt->setStyleSheet("QTreeView::indicator:checked {image: url(path);}");

    so when the checkbox is checked the image will be loaded.
    u have to create a image and load it into ur .pro file

    hope it helps
    Bala

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

    prajesh (25th February 2010)

  7. #6
    Join Date
    Feb 2010
    Location
    INDIA
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: checkbox implementation in QTableWidget display issue

    Hello Bala

    I am sorry to disturb you again.

    With image url, Its not at all working for me. Please check the code below to confirm any error made in code

    QTableWidget* m_GridWgt = new QTableWidget(3,3);
    QTableWidgetItem* qItem = new QTableWidgetItem();
    qItem->setFlags(Qt::ItemIsEnabled|Qt::ItemIsUserCheckabl e);
    qItem->setCheckState(Qt::Checked);
    m_GridWgt ->setStyleSheet("QTableWidget::indicator:checked {image: url(D:\checkbox.png);}");
    m_GridWgt->setItem(i, col, qItem);
    Setting background color is working fine for me . m_GridWgt ->setStyleSheet("QTableWidget::indicator:checked {background-color:blue;}");

    To confirm I have tried with below code

    QTableWidget* m_GridWgt = new QTableWidget(3,3);
    QCheckBox* qItem = new QCheckBox();
    qItem->setCheckState(Qt::Checked);
    m_GridWgt ->setStyleSheet("QCheckBox::indicator:checked {image: url(D:\checkbox.png);}");
    m_GridWgt->setItem(i, col, qItem);
    This is also not working for me.
    To double check the problem is with image, I load image image with another QT application and is getting fine.

    Do you see any wierdness in code? Is this has effect only with QTableview?

    I am attaching the image I used ,
    thx
    Prajesh
    Attached Images Attached Images
    Last edited by prajesh; 26th February 2010 at 06:27. Reason: used image also attached

  8. #7
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: checkbox implementation in QTableWidget display issue

    hi prajesh,

    Try this
    Qt Code:
    1. m_GridWgt->setStyleSheet("QTableWidget::indicator:checked {background-image:url(:/check-box.png);}");
    To copy to clipboard, switch view to plain text mode 
    this will surely work.
    i hav tested it out.
    pls resize ur image to there.

    steps:
    1) add the image in qrc file [do u know how to add to the resource file?]
    2) then apply the stylesheet
    dont forget to resize the image to fit within checkbox

    hope it helps
    Bala

  9. #8
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: checkbox implementation in QTableWidget display issue

    m_GridWgt ->setStyleSheet("QTableWidget::indicator:checked {image: url(D:\checkbox.png);}");
    pls add the imagefile to the resource file

    To add a image to a resource file
    steps :
    right click on ur project . click add new.
    then select Qt Resource file
    then give a name
    press ok.
    then click add ->addprefix
    let it be default.
    and again click add-> addfiles
    select ur file
    remove the prefix text."/new/prefix1"

    ur done.

    then use the stylesheet.

    i hav attached the checkbox image to fit within table's checkbox;
    pls refer the attachments

    or resize ur old image to fit.

    hope it helps
    Bala
    Attached Images Attached Images
    Last edited by BalaQT; 26th February 2010 at 07:48.

  10. #9
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: checkbox implementation in QTableWidget display issue

    The image should be on ur project folder [copy the checkbox image to ur projects folder]

    have u tried?
    Bala

  11. #10
    Join Date
    Feb 2010
    Location
    INDIA
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: checkbox implementation in QTableWidget display issue

    Hello Bala,

    As you siad , I resize the image and added as resource file. But unfortunately I couldnt work fine. Do you see the same check box in the image or windows by default check box. I pointed out this because, in windows checkbox is visible even with out set style sheet. The problem is when we run on WCE target.

    In Windows Do you see the same checkbox with tick color green?

    Is it possible to share your code?

    thx
    Prajesh

  12. #11
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: checkbox implementation in QTableWidget display issue

    In Windows Do you see the same checkbox with tick color green?
    yeah its working
    i hav attached here

    Bala
    Attached Files Attached Files

  13. #12
    Join Date
    Feb 2010
    Location
    INDIA
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: checkbox implementation in QTableWidget display issue

    Hello Bala,

    Thanks a lot for your reply. With your code and settings it is working fine for me. I am using VS and may be the problem with mocing files. I will check .

    Thanks a lot
    Prajesh

Similar Threads

  1. Accessing check state of CheckBox in QTableWidget
    By lnxusr in forum Qt Programming
    Replies: 6
    Last Post: 22nd November 2009, 01:13
  2. QTableWidget latout issue
    By AviMittal in forum Qt Programming
    Replies: 0
    Last Post: 25th June 2009, 15:12
  3. Tray context menu display issue
    By r2hubert in forum Qt Programming
    Replies: 1
    Last Post: 7th July 2008, 20:15
  4. Replies: 2
    Last Post: 5th June 2008, 21:32
  5. QTableWidget Resize issue
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2008, 20:08

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.