Results 1 to 4 of 4

Thread: Align a QPushButton in the cellwidget of QTableWidget

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Align a QPushButton in the cellwidget of QTableWidget

    I've created a custom class(DeviceState_Indicator) which inherits QPushButton. I want to use that as an LED indicator and I'm successful in doing that. Now I've placed that widget in a cell of a QTableWidget.

    Qt Code:
    1. for(int iCount = 0; iCount < NUM_OF_DEVICES; iCount++)
    2. {
    3. oDeviceStateIndication[iCount] = new DeviceState_Indicator(0, INDICATOR_GREEN);
    4. oDevStatePanel->setCellWidget(iCount, 2, oDeviceStateIndication[iCount]);
    5. }
    To copy to clipboard, switch view to plain text mode 

    The problem is, I'm unable to align the DeviceState_Indicator widget to the center (as shown in the pic attached). How do I align it to center?
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Align a QPushButton in the cellwidget of QTableWidget

    As fas as I know, the widget takes the whole space of the cell, so the custom widget has to paint itself centered. Or you insert QWidget which has a layout, spacers and the LED-Widget. But this would be madness. Alter your LED class that is paints the "image" centered.

  3. #3
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Align a QPushButton in the cellwidget of QTableWidget

    Quote Originally Posted by Lykurg View Post
    Alter your LED class that is paints the "image" centered.
    It's not an image, it's a QPushButton. I'm not getting anything that gives me options to align/space/set margin.


    Is there any widget or something (which is not an image) which I can use as an LED indicator inside a QTableWidget cell?

    Qt Code:
    1. #ifndef DEVICESTATE_INDICATOR_H
    2. #define DEVICESTATE_INDICATOR_H
    3.  
    4. #include <QPushButton>
    5. #include <QString>
    6.  
    7. #define INDICATOR_GREEN "background-color: green; border-radius: 7px; "
    8. #define INDICATOR_RED "background-color: red; border-radius: 7px; "
    9. #define INDICATOR_YELLOW "background-color: yellow; border-radius: 7px; "
    10. #define INDICATOR_GRAY "background-color: lightGray; border-radius: 7px; "
    11.  
    12.  
    13. class DeviceState_Indicator : public QPushButton
    14. {
    15. Q_OBJECT
    16. public:
    17. explicit DeviceState_Indicator(QWidget *parent, QString Indicator_Color);
    18.  
    19. signals:
    20.  
    21. public slots:
    22.  
    23. };
    24.  
    25. #endif // DEVICESTATE_INDICATOR_H
    To copy to clipboard, switch view to plain text mode 

    Thank you.
    Last edited by rawfool; 3rd May 2012 at 07:50.

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Align a QPushButton in the cellwidget of QTableWidget

    Question is, what for you need it to be a button?

    Simple row delegate will solve all your issues with painting and combined with cellActivated() signal it will act as button.
    What else do you need?

Similar Threads

  1. How to set focus to QTableWidget's cellWidget
    By danczer in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2011, 17:12
  2. QtableWidget moving cellWidget
    By hubipet in forum Qt Programming
    Replies: 0
    Last Post: 22nd October 2010, 08:06
  3. Using QPushButton in QTableWidget
    By arpspatel in forum Qt Programming
    Replies: 2
    Last Post: 1st September 2010, 01:26
  4. QTableWidget & cellWidget : some pointers
    By prashant in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2009, 11:48
  5. Replies: 0
    Last Post: 2nd May 2008, 08:57

Tags for this Thread

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.