Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, September 2006
QTableWidget : highlighting of cell when clicked


Message 1 in thread

hi,

I have created spread sheet kind of thing using QTableWidget and
QTableItemWidget and QTableView.

but, when I single click on the any cell, it not highlighting??
what can be the problem?

how can we make only borders to get bold when clicked on any cell??

Regards
Sridhar Jamalpur

Message 2 in thread

Sridhar jamalpur wrote:
> hi,
> 
> I have created spread sheet kind of thing using QTableWidget and
> QTableItemWidget and QTableView.
> 
> but, when I single click on the any cell, it not highlighting??
> what can be the problem?

I have no problems with this. If I click on a cell in a widget I get
normal highlighting. See the attached Table.java example

> how can we make only borders to get bold when clicked on any cell??

If you want to change how a cell is rendered you need to reimplement the
   QItemDelegate used to draw the table cells. The listwidget in the
launcher does this, so you can have a look at the file
com/trolltech/launcher/Delegate.java and look in the
public void paint(QPainter, QStyleOptionViewItem, QModelIndex) function.

I hope this helps,
Gunnar

import com.trolltech.qt.*;
import com.trolltech.qt.*;
import com.trolltech.qt.gui.*;

import java.util.*;

public class Table extends QTableWidget {

    public Table(QWidget parent) {
        super(parent);
        setColumnCount(10);
        setRowCount(10);

        for (int c=0; c<10; ++c) {
            for (int r=0; r<10; ++r) {
                QTableWidgetItem item = new QTableWidgetItem("row=" + r + ", col=" + c);
                setItem(r, c, item);
            }
        }
    }


    public static void main(String args[]) {
        QApplication.initialize(args);

        QWidget root = new QWidget();

        QComboBox behaviour  = new QComboBox(root);
        behaviour.addItem("Items");
        behaviour.addItem("Row");
        behaviour.addItem("Columns");

        QComboBox mode = new QComboBox(root);
        mode.addItem("NoSelection");
        mode.addItem("SingleSelection");
        mode.addItem("MultiSelection");
        mode.addItem("ExtendedSelection");
        mode.addItem("ContiguousSelection");

        Table t = new Table(root);

        QVBoxLayout box = new QVBoxLayout(root);
        box.addWidget(behaviour);
        box.addWidget(mode);
        box.addWidget(t);

        behaviour.activatedIndex.connect(t, "setSelectionBehavior(int)");
        mode.activatedIndex.connect(t, "setSelectionMode(int)");

        root.show();

        behaviour.setCurrentIndex(0);
        mode.setCurrentIndex(4);


        QApplication.exec();
    }

}