PDA

View Full Version : how to implement it ?



qtopiahooo
25th October 2006, 04:05
hi, all

i want to implement a widget like the following, which is like a Qtabbar:

________________
|_5_|_6_|_7_|_8_| |>

the left and right are two toolbuttons(i cannot draw the left button). in the middle are 4 horizontal grid to show 4 texts.

if the left toolbutton is pressed, the middle will show the previous 4 texts before the current leftmost text such as 1,2,3 and 4. if the right toolbutton is pressed, the middle will show the next 4 texts after the current rightmost text such as 9,10,11 and 12.

and the count of the texts can be specified.

any help is appreciated.

wysota
25th October 2006, 07:45
Depends if you need those button to be tabs or not. If not, then this should be very easy. Create six buttons and place them in a horizontal layout (you can use a button group to ease your job). The rightmost and leftmost buttons will be used to do the "scrolling" - connect their clicked() signal to a custom slot and in the slot modify the range of numbers displayed. Then connect the button group's clicked() signal to a custom slot and in that slot emit a custom signal with the number of the button clicked (mapped according to the range), for example:

/**
* connected to QButtonGroup::clicked(int)
*/
void wgt::clickedSlot(int c){
emit activated(c+leftmostid);
}

/**
* connected to scroller's clicked()
*/
void wgt::scrollerClicked(){
leftmostid+=sender()==rightScrollButton ? 4 : -4;
updateButtons();
}

void wgt::updateButtons(){
button1->setText(QString::number(leftmost));
button2->setText(QString::number(leftmost+1));
button3->setText(QString::number(leftmost+2));
button4->setText(QString::number(leftmost+3));
}

qtopiahooo
25th October 2006, 10:37
wysota, thanks very much.

I know what you mean.

now what i want to do is to implement it as a widget such as QTabbar or QSpinBox, so that i can integrate it into Qt Designer and use it by applications conveniently.

any suggestion about it ? thanks in advance.

wysota
25th October 2006, 17:01
Just wrap it into a QWidget and create a Designer plugin out of it.