PDA

View Full Version : Qpixmaps in Qtablewidget hides untill i select the cell?



Dreamerzz
22nd June 2011, 18:22
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

Rachol
22nd June 2011, 18:29
Can you provide some code that shows how you populate the table?

Dreamerzz
22nd June 2011, 18:52
ui->setupUi(this);
ui->tableWidget->setSpan(0,0,3,1);
//-------------
// IMAGE [QLABEL->PIXMAP]
//--------------
QLabel *label00 = new QLabel();
label00->setPixmap(QPixmap(":/pic.png"));
label00->setScaledContents(true);
ui->tableWidget->setCellWidget(0,0,label00);

Theres my label for the pixmap. :confused:

Rachol
22nd June 2011, 19:17
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:


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

for(int i = 0; i < 10;++i)
{
for(int j = 0; j < 10;++j)
{
QLabel *labelij = new QLabel();
labelij->setPixmap(QPixmap("3.png"));
labelij->setScaledContents(true);
ui->tableWidget->setCellWidget(i,j,labelij);
}
}
}

I got all the pixmaps without a problem

Dreamerzz
22nd June 2011, 20:00
Wait i have the exact same thing though, so maybe its an issue with my settings in the designer?


<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>833</width>
<height>392</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableWidget" name="tableWidget">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="textElideMode">
<enum>Qt::ElideMiddle</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<property name="gridStyle">
<enum>Qt::DashLine</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="cornerButtonEnabled">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<row>
<property name="text">
<string>New Row</string>
</property>
</row>
<row>
<property name="text">
<string>New Row</string>
</property>
</row>
<row>
<property name="text">
<string>New Row</string>
</property>
</row>
<column>
<property name="text">
<string>New Column</string>
</property>
</column>
<column>
<property name="text">
<string>New Column</string>
</property>
</column>
<column>
<property name="text">
<string>New Column</string>
</property>
</column>
<column>
<property name="text">
<string>New Column</string>
</property>
</column>
<column>
<property name="text">
<string>New Column</string>
</property>
</column>
<column>
<property name="text">
<string>New Column</string>
</property>
</column>
<column>
<property name="text">
<string>New Column</string>
</property>
</column>
<item row="1" column="0">
<property name="text">
<string/>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>833</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

Rachol
22nd June 2011, 20:12
I have used your ui file in my project and it worked...

Santosh Reddy
22nd June 2011, 20:31
Try this

ui->tableWidget->setCellWidget(0,0,label00);
ui->tableWidget->resizeColumnsToContents();
ui->tableWidget->resizeRowsToContents();

Dreamerzz
22nd June 2011, 20:44
That is really weird, it still isnt working for me... hm :confused:

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
http://i.imgur.com/zymFt.png

Rachol
22nd June 2011, 20:49
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?

Dreamerzz
23rd June 2011, 14:46
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