Results 1 to 10 of 10

Thread: Qpixmaps in Qtablewidget hides untill i select the cell?

  1. #1
    Join Date
    Jun 2011
    Posts
    19
    Thanks
    3

    Default Qpixmaps in Qtablewidget hides untill i select the cell?

    How can i make the pixmap(label) appear in the table without me having to click and select the cell it is in first?

    Thanks

  2. #2
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Qpixmaps in Qtablewidget hides untill i select the cell?

    Can you provide some code that shows how you populate the table?

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

    Dreamerzz (22nd June 2011)

  4. #3
    Join Date
    Jun 2011
    Posts
    19
    Thanks
    3

    Default Re: Qpixmaps in Qtablewidget hides untill i select the cell?

    Qt Code:
    1. ui->setupUi(this);
    2. ui->tableWidget->setSpan(0,0,3,1);
    3. //-------------
    4. // IMAGE [QLABEL->PIXMAP]
    5. //--------------
    6. QLabel *label00 = new QLabel();
    7. label00->setPixmap(QPixmap(":/pic.png"));
    8. label00->setScaledContents(true);
    9. ui->tableWidget->setCellWidget(0,0,label00);
    To copy to clipboard, switch view to plain text mode 

    Theres my label for the pixmap.

  5. #4
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Qpixmaps in Qtablewidget hides untill i select the cell?

    All right. I have just created a new project in Qt Creator. Used the template for Gui Application. I have added QTableWidget into GUI and set rowCount and columnCount to 10. Then in MainWindow's constructor I did that:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. for(int i = 0; i < 10;++i)
    8. {
    9. for(int j = 0; j < 10;++j)
    10. {
    11. QLabel *labelij = new QLabel();
    12. labelij->setPixmap(QPixmap("3.png"));
    13. labelij->setScaledContents(true);
    14. ui->tableWidget->setCellWidget(i,j,labelij);
    15. }
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    I got all the pixmaps without a problem

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

    Dreamerzz (22nd June 2011)

  7. #5
    Join Date
    Jun 2011
    Posts
    19
    Thanks
    3

    Default Re: Qpixmaps in Qtablewidget hides untill i select the cell?

    Wait i have the exact same thing though, so maybe its an issue with my settings in the designer?

    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>MainWindow</class>
    4. <widget class="QMainWindow" name="MainWindow">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>833</width>
    10. <height>392</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>MainWindow</string>
    15. </property>
    16. <widget class="QWidget" name="centralWidget">
    17. <layout class="QVBoxLayout" name="verticalLayout">
    18. <item>
    19. <widget class="QTableWidget" name="tableWidget">
    20. <property name="frameShape">
    21. <enum>QFrame::NoFrame</enum>
    22. </property>
    23. <property name="frameShadow">
    24. <enum>QFrame::Plain</enum>
    25. </property>
    26. <property name="lineWidth">
    27. <number>0</number>
    28. </property>
    29. <property name="selectionMode">
    30. <enum>QAbstractItemView::SingleSelection</enum>
    31. </property>
    32. <property name="textElideMode">
    33. <enum>Qt::ElideMiddle</enum>
    34. </property>
    35. <property name="showGrid">
    36. <bool>false</bool>
    37. </property>
    38. <property name="gridStyle">
    39. <enum>Qt::DashLine</enum>
    40. </property>
    41. <property name="wordWrap">
    42. <bool>true</bool>
    43. </property>
    44. <property name="cornerButtonEnabled">
    45. <bool>false</bool>
    46. </property>
    47. <attribute name="horizontalHeaderVisible">
    48. <bool>false</bool>
    49. </attribute>
    50. <attribute name="verticalHeaderVisible">
    51. <bool>false</bool>
    52. </attribute>
    53. <row>
    54. <property name="text">
    55. <string>New Row</string>
    56. </property>
    57. </row>
    58. <row>
    59. <property name="text">
    60. <string>New Row</string>
    61. </property>
    62. </row>
    63. <row>
    64. <property name="text">
    65. <string>New Row</string>
    66. </property>
    67. </row>
    68. <column>
    69. <property name="text">
    70. <string>New Column</string>
    71. </property>
    72. </column>
    73. <column>
    74. <property name="text">
    75. <string>New Column</string>
    76. </property>
    77. </column>
    78. <column>
    79. <property name="text">
    80. <string>New Column</string>
    81. </property>
    82. </column>
    83. <column>
    84. <property name="text">
    85. <string>New Column</string>
    86. </property>
    87. </column>
    88. <column>
    89. <property name="text">
    90. <string>New Column</string>
    91. </property>
    92. </column>
    93. <column>
    94. <property name="text">
    95. <string>New Column</string>
    96. </property>
    97. </column>
    98. <column>
    99. <property name="text">
    100. <string>New Column</string>
    101. </property>
    102. </column>
    103. <item row="1" column="0">
    104. <property name="text">
    105. <string/>
    106. </property>
    107. </item>
    108. </widget>
    109. </item>
    110. </layout>
    111. </widget>
    112. <widget class="QMenuBar" name="menuBar">
    113. <property name="geometry">
    114. <rect>
    115. <x>0</x>
    116. <y>0</y>
    117. <width>833</width>
    118. <height>20</height>
    119. </rect>
    120. </property>
    121. </widget>
    122. <widget class="QToolBar" name="mainToolBar">
    123. <attribute name="toolBarArea">
    124. <enum>TopToolBarArea</enum>
    125. </attribute>
    126. <attribute name="toolBarBreak">
    127. <bool>false</bool>
    128. </attribute>
    129. </widget>
    130. <widget class="QStatusBar" name="statusBar"/>
    131. </widget>
    132. <layoutdefault spacing="6" margin="11"/>
    133. <resources/>
    134. <connections/>
    135. </ui>
    To copy to clipboard, switch view to plain text mode 

  8. #6
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Qpixmaps in Qtablewidget hides untill i select the cell?

    I have used your ui file in my project and it worked...

  9. #7
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Qpixmaps in Qtablewidget hides untill i select the cell?

    Try this
    Qt Code:
    1. ui->tableWidget->setCellWidget(0,0,label00);
    2. ui->tableWidget->resizeColumnsToContents();
    3. ui->tableWidget->resizeRowsToContents();
    To copy to clipboard, switch view to plain text mode 

  10. #8
    Join Date
    Jun 2011
    Posts
    19
    Thanks
    3

    Default Re: Qpixmaps in Qtablewidget hides untill i select the cell?

    That is really weird, it still isnt working for me... hm

    which version of QT? also maybe its the picture im using?


    Added after 9 minutes:


    @Santosh it still does not work.

    WHat is weird is that the image appears highlighted
    Last edited by Dreamerzz; 22nd June 2011 at 20:44.

  11. #9
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Qpixmaps in Qtablewidget hides untill i select the cell?

    if you aren't doing anything extra than what you have shown us, I can't quite get: what has selecting and clicking the QLabel has to do with rendering the pixmap. Can you post an image with the pixmap visible? Any pixmap?

  12. #10
    Join Date
    Jun 2011
    Posts
    19
    Thanks
    3

    Default Re: Qpixmaps in Qtablewidget hides untill i select the cell?

    well i added some other labels in other rows and columns, also look above to post#8 to see what i see immediately after running

Similar Threads

  1. Replies: 1
    Last Post: 7th December 2009, 18:56
  2. Replies: 1
    Last Post: 23rd October 2009, 22:48
  3. How to select a cell in a QTableView
    By JeanC in forum Qt Programming
    Replies: 6
    Last Post: 6th February 2008, 13:20
  4. QTableWidget row select
    By nowire75 in forum Newbie
    Replies: 4
    Last Post: 23rd December 2007, 18:59
  5. Select None in QTableWidget
    By Rayven in forum Qt Programming
    Replies: 2
    Last Post: 9th June 2006, 14:10

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.